从GridView的页面导航离开后维持当前的GridView页面索引 [英] Maintaining GridView current page index after navigating away from Gridview page

查看:87
本文介绍了从GridView的页面导航离开后维持当前的GridView页面索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对ASP.NET Web窗体的GridView我已经绑定到数据源,并将其设置有10条记录每页。

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.

我也有在GridView,使得用户可以导航到另一页(详情页)从列表中的超链接列。在详细信息页面,他们有后退按钮返回到GridView页

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

修改结果
只是为了澄清查询

Edit
Just to clarify the query

我要寻找关于如何指定页面索引之后数据绑定设置GridView的服务器端样品code片段。这样做是为了确保在用户导航到他们在同一页上的索引。

I am looking for sample code snippet on the Server Side on how to specify the page index to set the GridView after data binding. The idea is to ensure the user navigates to the same page index they were on.

推荐答案

在您的处置三个基本选项:查询字符串,会话,饼干。他们每个人都有自己的缺点和长​​处:

The three basic options at your disposal: query string, session, cookie. They each have their drawbacks and pluses:


  1. 使用查询字符串将要求您格式化导致页面的gridview的各个环节有在查询字符串中正确的信息(这可能最终会被不仅仅是一个页码以上)。

  2. 使用会话如果你确定每个浏览器实例会想要去到相同的GridView会的工作,否则,你将有这是唯一可识别到有问题的GridView的每个页面的一些ID密钥来标记你的会话变量。这可能会导致很多的变数,可能是完全不可取的会话管理,其中大部分将不得不超时只。
  3. 来到期
  4. 使用一个Cookie需要类似使用Cookie的数据存储在一个键/数据矩阵(优化的哈希表可能用于此工作)的东西。它不会被推荐给对您所跟踪的每个网页的GridView一个单独的cookie的名称,而是有存放了正在跟踪的所有GridView的页面和内具有键/值结构中的数据的通用名称的cookie。

编辑:在设置页面索引一小code片段

A small code snippet on setting the page index.

protected void Page_Load(object sender, EventArgs e)
{
    if(!IsPostBack)
    {
        try
        {
            if(HttpContext.Current.Request["myGVPageId"] != null])
            {
                myGridview.PageIndex = Convert.ToInt32(HttpContext.Current.Request["myGVPageId"]);
            }
        }
        catch(Exception ex)
        {
            // log it
        }
    }
}

这篇关于从GridView的页面导航离开后维持当前的GridView页面索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆