-
grid sort
Hi,
in my asp.net project, I am populating a datagrid ( on a web form ) using a datareader (GetAllTrades). See below...
With dgNewTrades
.DataSource = oCatTMS.GetAllTrades
.DataKeyField = "tnum"
.DataBind()
End With
The AllowSorting property is set to true.
But I can not sort the data. When I place the mouse over the column names, I will not get the hyperlinks.
Any thoughts?
Thanks
-
There is quite a lot to do before sorting will work, as well as allowsorting=true you will need to set an on sort event such as
OnSortCommand="sort_grid"
Code:
Sub Sort_Grid(ByVal sender As Object, ByVal e As DataGridSortCommandEventArgs)
SortExpression = e.SortExpression.ToString()
gridLeaderBoard.DataSource = createDataSource()
gridLeaderBoard.DataBind()
End Sub
When you want to sort you have to resort the datasource and then rebind the grid to it's datasource. I do this by loading data from my database into a datatable, then creating a dataview (sorted by sortExpression).
Hope this helps.