Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 22nd, 2004, 06:15 PM
Authorized User
 
Join Date: Jul 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default DataView Not Sorting

Hello,

I am using a DataView that has 100 records in it. I am also sorting the DataView with sort method. This DataView is also displayed in a DataGrid on a web page. The DataView displays the data sorted in the DataGrid, so that is working OK. However, the problem is that when I get a field value from a row from this DataView, the data is not sorted. Row 0 always has the same value. Basically, I want to select a row in DataGrid and get other data from the DataView. Currently, the DataView rows do not match what is shown in the DataGrid, becuase the DataView is not sorted, but the datagrid is. I am using MS Visual C# .Net.

Here is some of my code:

DataView dvSearchResults = (DataView) Session[_ViewStateCalSearchResults];

DataRow rowCase = dvSearchResults.Table.Rows[0];
string test = rowCase["PersonName"].ToString();

dvSearchResults.Sort = strNewSortExpr + " " + strSortDir;

rowCase = dvSearchResults.Table.Rows[0];
string test2 = rowCase["PersonName"].ToString();

Thanks,

Paul
 
Old December 23rd, 2004, 12:59 PM
tnd tnd is offline
Authorized User
 
Join Date: Jun 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It looks like you are accessing row[0] of the table the view is based on. You need to just use dataview[0] instead of dataview.table.rows[0]

 
Old December 23rd, 2004, 08:53 PM
Authorized User
 
Join Date: Jul 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your input. I have been reading that I should be using the default view, which can be sorted. Tables can not be sorted and its difficult to change the order of them. I wrote a little VB app where the sort method works on the default DataView.

Dim dvCases as DataView
Dim dtCaseData As New DataTable
dvCases = dtCaseData.DefaultView
dvCases.Sort = "name ASC"

Anybody know how to rewrite this in C#?
 
Old December 27th, 2004, 06:30 PM
Authorized User
 
Join Date: Jul 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is the code that I have now, but this is still not sorting.

DataSet dsSearchResults = GetProceedings(dtSelectedDate, ddlTime.SelectedValue.Trim(), ddlRoom.SelectedValue.ToString(), strJudge);

DataView dvSearchResults = dsSearchResults.Tables[0].DefaultView;
DataRow rowCase = dvSearchResults.Table.Rows[0];
dvSearchResults.Sort = "PersonName ASC";

Any help would be much appreciated on why the sort method is not sorting.

Thank you,

Paul





Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting Datefield in a DataView Wanda ASP.NET 2.0 Basics 0 January 11th, 2007 04:13 PM
Numeric sorting in dataview ghari ASP.NET 1.0 and 1.1 Professional 12 November 15th, 2006 12:40 PM
Sorting With dataView anubhav.kumar ADO.NET 1 March 17th, 2005 05:06 AM
Datagrid sorting by non alphabetical sorting? LLAndy VS.NET 2002/2003 1 July 15th, 2004 01:20 AM
DataView vivi C# 4 November 10th, 2003 01:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.