sorting and paging with gridview asp.net

前端 未结 5 1355
日久生厌
日久生厌 2020-11-27 03:15

I\'m trying to get a gridview to sort and page manually with no success.

The problem is that when a user clicks the column they want to sort, it sorts that page, but

5条回答
  •  北海茫月
    2020-11-27 03:28

    I found a much easier way, which allows you to still use the built in sorting/paging of the standard gridview...

    create 2 labels. set them to be visible = false. I called mine lblSort1 and lblSortDirection1

    then code 2 simple events... the page sorting, which writes to the text of the invisible labels, and the page index changing, which uses them...

    Private Sub gridview_Sorting(sender As Object, e As GridViewSortEventArgs) Handles gridview.Sorting
    lblSort1.Text = e.SortExpression
    lblSortDirection1.Text = e.SortDirection
    End Sub
    
    Private Sub gridview_PageIndexChanging(sender As Object, e As GridViewPageEventArgs) Handles gridview.PageIndexChanging
        gridview.Sort(lblSort1.Text, CInt(lblSortDirection1.Text))
    End Sub
    

    this is a little sloppier than using global variables, but I've found with asp especially that global vars are, well, unreliable...

提交回复
热议问题