为什么Gridview Page IndexChanging只能在f / w方向工作? [英] Why does Gridview Page IndexChanging works in f/w direction only?
本文介绍了为什么Gridview Page IndexChanging只能在f / w方向工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
早安伙伴们,
我的Gridview页面仅适用于第1页到第2页和第3页......
但是如果我我在第3页并点击第2或第1页它没有做任何事情,而只是坐在第3页本身。
这是我的代码
< asp:GridView ID = gdvAll runat = server AllowPaging = true PageSize = 10 AllowSorting = true
Style = vertical-align:middle; HorizontalAlign = Center OnPageIndexChanging = ongdvPageIndex_Clicked
AutoGenerateColumns = false OnSelectedIndexChanged = OnSelectedIndexChanged EnableSortingAndPagingCallbacks = true
CssClass = Grid AlternatingRowStyle-CssClass = alt PagerStyle-CssClass = pgr>
受保护的子ongdvPageIndex_Clicked (ByVal Sender As Object,ByVal e As GridViewPageEventArgs)
尝试
gdvAll.PageIndex = e.NewPageIndex
gdvAll.DataSource = ViewState(gdvAll)
gdvAll.DataBind()
Catch ex As Excep
LogError.LogErrorIntoTextFile(例如,ongdvPage_Clicked())
结束尝试
结束子
任何人都可以在Gridview中找出这种奇怪的页面行为吗?
解决方案
我相信你的ViewState(gdvAll)是来自另一个子程序的数据集与某种SQL或其他。此代码将按升序或降序对数据进行排序,以减轻您的页面问题:
受保护的 Sub gdvAll_OnSorting( ByVal sender As Object , ByVal e As GridViewSortEventArgs)句柄 GridView1.Sorting
Dim sortingdirection,sortby
If e.SortDirection = ASC 然后
sortingdirection = DESC
Else
sortingdirection = ASC
结束 如果
sortby = e.SortExpression &安培; & sortingdirection
Dim MyDataSet As 新 DataSet = ViewState( gdvAll)
Dim MyDataTable As New DataTable()
MyDataTable = MyDataSet.Tables( 0 )
Dim MyDataView As 新 DataView(MyDataTable)
MyDataView.Sort = sortby
gdvAll.DataSource = ViewState( gdvAll)
GridView1.DataBind()
结束 < span class =code-keyword> Sub
< asp:GridView ID = gdvAll runat = server AllowPaging = < span class =code-string> true OnPageSize = 10 AllowSorting = true OnSorting = gdvAll1_OnSorting
Style = vertical-align:middle; HorizontalAlign = Center OnPageIndexChanging = ongdvPageIndex_Clicked
AutoGenerateColumns = false OnSelectedIndexChanged = OnSelectedIndexChanged EnableSortingAndPagingCallbacks = true
CssClass = 网格 AlternatingRowStyle-CssClass = alt PagerStyle-CssClass = pgr>
Good Morning guys,
My Gridview page only works from 1st page to 2nd and to 3rd...
But if I am on 3rd page and click on 2nd or 1st it doesn't do anything, instead just sits on page 3 itself.
Here is my code
<asp:GridView ID="gdvAll" runat="server" AllowPaging="true" PageSize="10" AllowSorting="true"
Style="vertical-align: middle;" HorizontalAlign="Center" OnPageIndexChanging ="ongdvPageIndex_Clicked"
AutoGenerateColumns="false" OnSelectedIndexChanged="OnSelectedIndexChanged" EnableSortingAndPagingCallbacks="true"
CssClass="Grid" AlternatingRowStyle-CssClass="alt" PagerStyle-CssClass="pgr">
Protected Sub ongdvPageIndex_Clicked(ByVal Sender As Object, ByVal e As GridViewPageEventArgs) Try gdvAll.PageIndex = e.NewPageIndex gdvAll.DataSource = ViewState("gdvAll") gdvAll.DataBind() Catch ex As Exception LogError.LogErrorIntoTextFile(ex, "ongdvPage_Clicked()") End Try End Sub
Can anyone figure out this weird behavior of pages in Gridview?
解决方案
I believe your ViewState("gdvAll") is a dataset from another Subroutine with some sort of SQL or other. This code will sort the data by Ascending or Descending alleviating you Page Problem:
Protected Sub gdvAll_OnSorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs) Handles GridView1.Sorting Dim sortingdirection, sortby If e.SortDirection = "ASC" Then sortingdirection = "DESC" Else sortingdirection = "ASC" End If sortby = e.SortExpression & " " & sortingdirection Dim MyDataSet As New DataSet = ViewState("gdvAll") Dim MyDataTable As New DataTable() MyDataTable = MyDataSet.Tables(0) Dim MyDataView As New DataView(MyDataTable) MyDataView.Sort = sortby gdvAll.DataSource = ViewState("gdvAll") GridView1.DataBind() End Sub
<asp:GridView ID="gdvAll" runat="server" AllowPaging="true" OnPageSize="10" AllowSorting="true" OnSorting="gdvAll1_OnSorting" Style="vertical-align: middle;" HorizontalAlign="Center" OnPageIndexChanging ="ongdvPageIndex_Clicked" AutoGenerateColumns="false" OnSelectedIndexChanged="OnSelectedIndexChanged" EnableSortingAndPagingCallbacks="true" CssClass="Grid" AlternatingRowStyle-CssClass="alt" PagerStyle-CssClass="pgr">
这篇关于为什么Gridview Page IndexChanging只能在f / w方向工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文