|
-
Mar 17th, 2003, 11:31 PM
#1
Thread Starter
Addicted Member
Sorting Datasets: Can it be done?
I have a dataset which reads in an XML file containing an address book. I want to be able to sort this address book into alphabetical order. I have currently been taking the data from the dataset and inserting then sorting it in a collection. But that is very in-efficient.
Is it possible to sort the dataset into alphabetical order from fields i define?
-
Mar 17th, 2003, 11:51 PM
#2
Just load the Dataset into a Dataview and sort it at the time. I don't have VS.NET on this computer but there should be an example either in the help or in the forums.
-
Jun 12th, 2003, 08:11 AM
#3
PowerPoster
I tried doing this but everytime I click to sort the datagrid comes up empty!
Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
SqlDataAdapter1.SelectCommand.Parameters("@strDepartment").Value = "web"
SqlDataAdapter1.Fill(Ds1)
DataGrid1.DataBind()
Cache.Insert("ds", Ds1, Nothing, DateTime.Now.AddMinutes(5), Caching.Cache.NoSlidingExpiration)
End If
End Sub
Private Sub DataGrid1_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles DataGrid1.SortCommand
Dim newdv As DataView = New DataView(Cache("ds"))
Dim SortExpression As String = e.SortExpression.ToString()
newdv.Sort = SortExpression & " asc"
DataGrid1.DataSource = newdv
DataGrid1.DataBind()
End Sub
End Class
-
Jun 12th, 2003, 08:57 AM
#4
Fanatic Member
Try sorting the DataTables contained within the dataset (using your DataView) before binding (ie - do it in your load event).
-
Jun 12th, 2003, 08:59 AM
#5
Fanatic Member
I think that the DataGrid has a property to allow sorting too, so you can also set that to True to allow your users to sort by any of the columns in your datagrid.
-
Jun 12th, 2003, 09:04 AM
#6
PowerPoster
Originally posted by VBCrazyCoder
I think that the DataGrid has a property to allow sorting too, so you can also set that to True to allow your users to sort by any of the columns in your datagrid.
Well ya! But you have to code it yourself!
-
Jun 12th, 2003, 09:26 AM
#7
Fanatic Member
Not if you have a custom Datagrid control
-
Jun 12th, 2003, 09:29 AM
#8
PowerPoster
-
Jun 12th, 2003, 10:22 AM
#9
Frenzied Member
You have to implement your own sorting routine for the Web DataGrid control. The Windows Form DataGrid sorting is free. Just click on the column header you want to sort. You can also sort on a specific column before you bind to the datagrid.
Code:
DataView dv = new DataView(ds.Tables["myTable"]);
dv.Sort = "columnName DESC";
dataGrid.DataSource = dv;
-
Jun 12th, 2003, 10:24 AM
#10
PowerPoster
Originally posted by DevGrp
You have to implement your own sorting routine for the Web DataGrid control. The Windows Form DataGrid sorting is free. Just click on the column header you want to sort. You can also sort on a specific column before you bind to the datagrid.
Code:
DataView dv = new DataView(ds.Tables["myTable"]);
dv.Sort = "columnName DESC";
dataGrid.DataSource = dv;
But then HOW do you figure out what Sort Direction was previously selected? And also how do you resolve the issue if the user switches columns? The first click doesn't sort when they change columns.
-
Jun 12th, 2003, 05:59 PM
#11
Frenzied Member
What are you referring to? The Web DataGrid control or the Winforms DataGrid control?
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
|