我需要帮助对 gridview 进行排序,下面是我的代码:
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
我目前得到:找不到列[我正在排序的任何列]
我是 VB 的新手,正在努力学习这一点,我无法使任何其他示例代码工作。
感谢您的帮助。
补充:其他代码:
在页面加载时我运行我的存储过程,然后它绑定数据:
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
存储过程查询:
GridView1.DataSource = dsData
GridView1.AllowSorting = True
GridView1.DataBind()
ASPX 代码:
<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>