Broodmdh
March 24th, 2006, 11:57 AM
I am trying to set up sorting for my datagrid, and I've followed several examples that I've found online but it still doesn't work. On the first page load, the datagrid is populated with a default query. The user then has the option to perform other queries which would populate the datagrid. All of the columns are bound at runtime, and all but one should be sortable. As things stand right now, my Sort sub never gets triggered. Here is my code:
<asp:datagrid id="dgResults" runat="server" CssClass="ControlText" Width="95%" OnSortCommand="dgResults_Sort" AllowSorting="True"></asp:datagrid>
Public Sub dgResults_Sort(ByVal sender As System.Object, ByVal e As DataGridSortCommandEventArgs) Handles dgResults.SortCommand
Dim dv As DataView = New DataView(CType(dgResults.DataSource, DataSet).Tables(0))
dv.Sort = e.SortExpression
dgResults.DataSource = dv
dgResults.DataBind()
End Sub
The datagrid is bound in another sub, which is also where the columns are created. What am I missing? I shouldn't have to requery the database every time a sort is performed, should I?
<asp:datagrid id="dgResults" runat="server" CssClass="ControlText" Width="95%" OnSortCommand="dgResults_Sort" AllowSorting="True"></asp:datagrid>
Public Sub dgResults_Sort(ByVal sender As System.Object, ByVal e As DataGridSortCommandEventArgs) Handles dgResults.SortCommand
Dim dv As DataView = New DataView(CType(dgResults.DataSource, DataSet).Tables(0))
dv.Sort = e.SortExpression
dgResults.DataSource = dv
dgResults.DataBind()
End Sub
The datagrid is bound in another sub, which is also where the columns are created. What am I missing? I shouldn't have to requery the database every time a sort is performed, should I?