1

を介してデータベースgridviewに接続されているaspがあります。コードビハインドにバインドしています。私も普通にやってますが、sqlLINQ

 AllowSorting="True"

そして、各列にソート式を設定します: ex-

                <asp:BoundField DataField="BorrowerDateOfBirth" HeaderText="Date Of Birth" 
                    DataFormatString="{0:d}" SortExpression="BorrowerDateOfBirth" >
                </asp:BoundField>

しかし、アプリケーションを実行し、列ヘッダーをクリックして並べ替えると、アプリケーションは次のような例外エラーを発生させます。

"GridView ' gridview1' は処理されなかった並べ替えイベントを発生させました。"

このエラーをオンラインで調べましたが、C# コードに関連する応答しか見つかりませんでした。それらを vb.net に変換しようとしましたが、エラーは解決しません。

vb.netでaspグリッドビューのソートを処理する方法を知っている人はいますか?

4

1 に答える 1

1

OnSorting=""プロパティを関数名に設定し、その関数でソートを処理する必要があります。これらの線に沿った何か

Protected Sub TaskGridView_Sorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs)  
    'Retrieve the table from the session object.
    Dim dt = TryCast(Session("table"), DataTable)
    If dt IsNot Nothing Then 
      'Sorting the data.
      dt.DefaultView.Sort = e.SortExpression & " " &  GetSortingDirection(e.SortExpression)
      TaskGridView.DataSource = Session("TaskTable")
      TaskGridView.DataBind()
    End If
End Sub

Private Function GetSortingDirection(ByVal column As String) As String
    ' By default, set the sort direction to ascending.
    Dim sortDirection = "ASC"
    ' Retrieve the last column that was sorted.
    Dim sortExpression = TryCast(ViewState("SortExpression"), String)
    If sortExpression IsNot Nothing Then
      ' Check if the same column is being sorted.
      ' Otherwise, the default value can be returned.
      If sortExpression = column Then
        Dim lastDirection = TryCast(ViewState("SortDirection"), String)
        If lastDirection IsNot Nothing _
          AndAlso lastDirection = "ASC" Then
          sortDirection = "DESC"
        End If
      End If
    End If
    ' Save new values in ViewState.
    ViewState("SortDirection") = sortDirection
    ViewState("SortExpression") = column
    Return sortDirection
End Function
于 2013-08-26T19:42:33.773 に答える