如果在使用C#单击后退按钮时在gridview中进行分页,如何保持在同一页面中 [英] How to stay in the same page if paging in gridview on clicking back button using C#
本文介绍了如果在使用C#单击后退按钮时在gridview中进行分页,如何保持在同一页面中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I have a GridView on ASP.NET web form which I have bound to a data source and set it to have 10 records per page.
I also have a hyper link column on the GridView, such that a user can navigate to another page (details page)
from the list. On the details page, they have "Back" button to return to the GridView page
I tried the below code but its not working
<pre lang="c#">protected void GridViewIndexChanging(object sender, GridViewPageEventArgs e)
{
myGridView.PageIndex = e.NewPageIndex;
Session["pageNumber"] = e.NewPageIndex;
}
if (!IsPostBack)
{
if (Session["pageNumber"] != null)
{
GridViewIndexChanged(myGridView, new GridViewPageEventArgs((int)Session["pageNumber"]));
}
}
我的尝试:
What I have tried:
I tried the above code but its not working
推荐答案
代替链接按钮,您需要使用超链接并在查询字符串中传递id。然后从该查询字符串参数中,您可以加载详细信息页面。如果您不想单独的数据库命中,则将完整对象放入会话并在重定向后重用会话。
链接按钮在gridview中使用另一个页面重定向如何? - DotNetFunda.com [ ^ ]
注意:如果您通过查询字符串发送id,请确保使用加密和解密查询字符串参数。
In place of link button you need to use Hyperlink and pass the id in query string.Then from that query string parameter you can load details page.If you don't want a separate database hit then put the complete object in a session and reuse the session after the redirection.
link button using in gridview another page redirect how? - DotNetFunda.com[^]
N.B:If you are sending the id by query string make sure you use encryption and decryption of query string parameters.
这篇关于如果在使用C#单击后退按钮时在gridview中进行分页,如何保持在同一页面中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文