I need help sorting a gridview, below is my code:
Protected Sub TaskGridView_Sorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs) Handles GridView1.Sorting
'Retrieve the table from the session object.
Dim dt As DataView = dsData.AsDataView
If dt IsNot Nothing Then
'Sort the data.
If (GridView1.SortDirection() = SortDirection.Ascending) Then
dt.Sort = e.SortExpression & " " & SortDirection.Descending
Else
dt.Sort = e.SortExpression & " " & SortDirection.Descending
End If
GridView1.DataSource = dt
GridView1.DataBind()
End If
I’m currently getting:
Cannot find column [Whatever Column I’m sorting]
I’m new to VB and struggling to learn this and I can’t make any of the other example code work.
Thank you for your help.
Added:
Other code:
ON page load I run my stored procedure and then it binds the data:
Dim objConn As IDbConnection = Nothing
Dim strBlder As New System.Text.StringBuilder
Dim providerID As String = Request.QueryString("ProviderID")
Dim providerName As String = Request.QueryString("ProviderName")
GridView1.PagerSettings.Mode = PagerButtons.NumericFirstLast
Stored Procedure Query:
GridView1.DataSource = dsData
GridView1.AllowSorting = True
GridView1.DataBind()
ASPX Code:
<asp:GridView ID="GridView1" runat="server" style="margin-right: 0px"
AllowPaging = "True" PageSize = "50" AllowSorting = "true">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:TemplateField HeaderText="Status"></asp:TemplateField>
</Columns>
</asp:GridView>
Replace
With