|
-
Nov 20th, 2008, 01:07 AM
#1
Thread Starter
Just Married
[2.0] Order data table
Hi friends let me know how to order datatable
Thanks
-
Nov 20th, 2008, 01:57 AM
#2
Re: [2.0] Order data table
No way to sort a DataTable is provided. If you need to sort the data in a DataTable then you normally do so via the DefaultView, which is a DataView. You set the Sort property, e.g. "Surname" or "Surname ASC" to sort in ascending order by surname or "DateOfBirth DESC" to sort in descending order by date of birth.
To access the data in sorted order you then loop through the DefaultView instead of the Rows collection. Note that any controls bound to the DataTable get their data from the DefaultView already, so they will honour the sort order.
If you absolutely must have a DataTable sorted a particular way then you should normally be doing that with your SQL code. If you can't for whatever reason then you can sort a DataView and then call its ToTable method, which will create a new DataTable with the same schema as the original and with the rows in the same order as the DataView.
-
Nov 20th, 2008, 05:05 AM
#3
Thread Starter
Just Married
Re: [2.0] Order data table
Can we sort data randomly? time by time
When page refresh the it show different data on page
-
Nov 20th, 2008, 06:31 AM
#4
Re: [2.0] Order data table
 Originally Posted by shakti5385
Can we sort data randomly? time by time
When page refresh the it show different data on page
Doesn't random kind of imply not sorted? You can't sort randomly. If you want a random order then you will have to select a random row one at a time until there are no rows left to select. The Unique Random Selections link in my signature can show you how to do that.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|