排序Gridview时找不到列

时间:2012-07-17 15:25:46

标签: vb.net visual-studio sorting gridview

我需要帮助排序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的新手并且正在努力学习这个并且我不能让任何其他示例代码工作。

感谢您的帮助。

添加了: 其他代码:

ON页面加载我运行我的存储过程,然后它绑定数据:

    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>

1 个答案:

答案 0 :(得分:0)

替换

If (GridView1.SortDirection() = SortDirection.Ascending) Then
    dt.Sort = e.SortExpression & " " & SortDirection.Descending
Else
    dt.Sort = e.SortExpression & " " & SortDirection.Descending
End If

使用

If (GridView1.SortDirection() = SortDirection.Ascending) Then
    dt.Sort = e.SortExpression & " ASC"
Else
    dt.Sort = e.SortExpression & " DESC"
End If