|
-
Oct 14th, 2002, 09:50 AM
#1
Thread Starter
Member
Sorting Data in DataGrid
Hi;
I am able to display the data from DB2 database in a DataGrid on a WebForm. But, I just can't figure out how to sort the data on the form. I did look in the MSDN library but it didn't help me much.
I did go to the "Property builder" of the datagrid and turned on the "Sorting Behavior" and I have put the "Sorting Expression" in the property builder also. But I think we need to put some code also to be able to sort the data during the run time.
So, could someone please let me know, what code I need to put to be able to sort the data?
thanks in advance
-
Oct 14th, 2002, 10:02 AM
#2
Member
when you click on the column header you fire of the Sort_command property. the e.SortExpression tells you which column has been clicked. Re populate the grid using this ie.
"select * from Customers Order By " & e.sortExpression
-
Oct 14th, 2002, 04:15 PM
#3
Thread Starter
Member
I kind of tried that........ but the code is as follows
Private Sub DataGrid1_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles DataGrid1.SortCommand
DataView1.Sort = e.SortExpression
DataGrid1.DataSource = DataView1
DataGrid1.DataBind()
End Sub
now; when click the column header while running the application to sort the data the page refreshes but nothing changes. So do you have any idea what would be the problem.
thanks
Jacob
-
Oct 15th, 2002, 04:20 AM
#4
Member
I'm not sure about your code, but this is how i do it. I initially populate the grid , then when the header is clicked run this:
Dim myDataSet As New DataSet()
Dim mySqlDataAdapter As SqlDataAdapter
mySqlDataAdapter = New SqlDataAdapter( _
"SELECT * From tbl_employee ORDER BY " & e.SortExpression, _
"Data Source=NTTEST;Initial Catalog=Payroll;User id=Sa;Pwd=;")
mySqlDataAdapter.Fill(myDataSet, "Person")
GrdRepairs.DataSource = myDataSet.Tables("Person")
GrdRepairs.DataBind()
I'm sure there maybe a better way of doing this but it works for me.
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
|