zoukankan      html  css  js  c++  java
  • gridview 翻页后保持排序

     1 Protected Sub gvdatalist_Sorting(ByVal sender As ObjectByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles gvdatalist.Sorting
     2
     3        GridViewSortExpression = e.SortExpression
     4
     5        Dim pageIndex As Integer = gvdatalist.PageIndex
     6        gvdatalist.DataSource = SortDataTable(dt, False)
     7        gvdatalist.DataBind()
     8        gvdatalist.PageIndex = pageIndex
     9
    10    End Sub

    11
    12    Private Property GridViewSortDirection() As String
    13        Get
    14            Return ViewState("SortDirection")
    15        End Get
    16        Set(ByVal Value As String)
    17            ViewState("SortDirection"= value
    18        End Set
    19    End Property

    20
    21
    22
    23    Private Property GridViewSortExpression() As String
    24        Get
    25            Return ViewState("SortExpression")
    26        End Get
    27        Set(ByVal Value As String)
    28            ViewState("SortExpression"= value
    29        End Set
    30    End Property

    31
    32
    33
    34    Private Function GetSortDirection() As String
    35
    36        Select Case GridViewSortDirection
    37
    38            Case "ASC"
    39                GridViewSortDirection = "DESC"
    40
    41                'Exit Function
    42
    43            Case "DESC"
    44
    45                GridViewSortDirection = "ASC"
    46
    47                ' Exit Function
    48            Case Else
    49                GridViewSortDirection = "ASC"
    50
    51        End Select
    52        Return GridViewSortDirection
    53
    54    End Function

    55
    56
    57
    58
    59    Protected Function SortDataTable(ByVal dataTable As DataTable, ByVal isPageIndexChanging As BooleanAs DataView
    60
    61        If Not dataTable Is Nothing Then
    62
    63            Dim dataView As DataView = New DataView(dataTable)
    64
    65            If GridViewSortExpression <> String.Empty Then
    66
    67                If isPageIndexChanging Then
    68
    69                    dataView.Sort = String.Format("{0} {1}", GridViewSortExpression, GridViewSortDirection)
    70
    71                Else
    72
    73                    dataView.Sort = String.Format("{0} {1}", GridViewSortExpression, GetSortDirection())
    74
    75                End If
    76
    77            End If
    78
    79            Return dataView
    80
    81        Else
    82
    83            Return New DataView()
    84
    85        End If
    86
    87    End Function

    88
    89    Protected Sub gvdatalist_PageIndexChanging(ByVal sender As ObjectByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvdatalist.PageIndexChanging
    90        Me.gvdatalist.PageIndex = e.NewPageIndex
    91        Me.gvdatalist.DataSource = SortDataTable(dt, True)
    92        Me.gvdatalist.DataBind()
    93        Me.drto.SelectedValue = e.NewPageIndex + 1
    94    End Sub
    我的淘宝店:http://hamby.taobao.com
  • 相关阅读:
    CodeForces979D:Kuro and GCD and XOR and SUM(Trie树&指针&Xor)
    HDU4188:RealPhobia (连分数的运用之一)
    从HDU2588:GCD 到 HDU5514:Frogs (欧拉公式)
    SPOJ:Eagle and Dogs(求树上每个点最远可以走到哪里---树的直径||DP)
    【字符串】BZOJ上面几个AC自动机求最为字串出现次数的题目
    codeforces round #405 B. Bear and Friendship Condition
    codeforces round #419 C. Karen and Game
    codeforces round #419 B. Karen and Coffee
    codeforces round #419 A. Karen and Morning
    【ZOJ 3609】Modular Inverse 最小乘法逆元
  • 原文地址:https://www.cnblogs.com/hambywu/p/1209384.html
Copyright © 2011-2022 走看看