如果在 Page_load 期间未加载网格,则 ASP.NET Gridview 分页不起作用。所有方法都试过了

发布于 2024-09-29 00:10:15 字数 658 浏览 0 评论 0原文

我有一个 gridview,单击按钮即可加载数据。由于某种原因,寻呼不起作用。寻呼号码会显示,但单击第 2、3 或 4 页不会带您到任何地方。单击它们后网格就会消失。之后,当我单击按钮生成网格时,网格出现,这次网格位于第 2 或第 3 页而不是第 1 页。

我在 page_indexing 上正确显示了以下内容。

    Protected Sub GV_Document_Hide_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GV_PSIDocument_Hide.PageIndexChanging
    GV_Document_Hide.PageIndex = e.NewPageIndex
End Sub

我什至尝试按照其他线程中的建议在 pageindexchanging 中添加 databind() 代码,但这没有任何区别。

我能做到这一点的唯一方法是通过在 page_load 上填充/加载网格。我必须分配数据源和每次都进行数据绑定,无论是否回发。我尝试了IsNotpostback,然后分页又失败了,

为什么gridview需要在分页正常工作的情况下每次都需要在page_load上加载?

I have a gridview which I load with data on click of a button. For some reason the paging did not work. The paging number shows up but clicking on page # 2, 3 or 4 does not take you anywhere. the grid just disappears on clicking them. right after that when i click the button to generate the grid, the grid came up this time the gird is on page 2 or 3 instead of 1.

I have the following on page_indexing properly.

    Protected Sub GV_Document_Hide_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GV_PSIDocument_Hide.PageIndexChanging
    GV_Document_Hide.PageIndex = e.NewPageIndex
End Sub

I even tried by adding the databind() code inside the pageindexchanging as suggested in other threads but that didn't make any difference.

The only way I could get this going was by populating/loading the grid on page_load. I have to assign datasource & databind it every time irrespective of even postbacks. I tried IsNotpostback then the paging failed again

Why does gridview needs loading on page_load every time if the paging needs to work properly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

过气美图社 2024-10-06 00:10:15

并不需要每次都进行Page_Load;但是当您更改页面时,您确实需要重新绑定到数据源,以便它可以加载新页面的新记录。如果您愿意,您可以在处理页面更改的事件中执行此操作。

It doesn't need Page_Load every time; but when you change the page, you do need to re-bind to the data source so it can load its new records for the new page. You can do that in the event handling the page changing, if you like.

ゃ懵逼小萝莉 2024-10-06 00:10:15

您在页面中使用更新面板吗? Obout 网格分页不适用于 MS UpdatePanel。您应该使用他们自己的面板: https://www.obout.com/ajaxpage/cp_howitworks.aspx< /a>
如果它不起作用,请尝试设置serialize = false。

Do you use Update panels in your page? Obout grids paging doesn't work with MS UpdatePanel. You should use their own panel: https://www.obout.com/ajaxpage/cp_howitworks.aspx
If it doesn't work try also to set serialize=false.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文