2010-11-09 38 views
0

我在数据库中有40条记录,但我通过使用网格面板在商店网格的每个页面中显示10条记录。如何在刷新asp.net中的网页后获取当前页面?

同样,我使用Ajax进行事件。问题是当我刷新页面或网格时,它显示第一页中的第一条记录。刷新数据时如何获取当前页面数据?

我该如何避免这个问题,任何人都可以帮助我?

回答

0

你需要在你的后端一个会话保留当前的指数(当你做你的Ajax请求更新),当您重新从该索引的页面开始。

+0

我已经完成了。但它没有绑定到特定的页面。这是代码:protected void Refresh_Click(object sender,StoreRefreshDataEventArgs e) { Refresh(); pgtCombo.PageIndex =(int)Session [“pgIndex”]; pgtCombo.PageSize =(int)Session [“pgSize”]; Session [“pgIndex”] = string.Empty; Session [“pgSize”] = string.Empty; } – user520946 2010-11-10 07:27:49

+0

您在服务器端使用哪种语言?您也应该重新标记您的问题以包含该问题,因为您现在试图解决的问题与此相关。 – Knubo 2010-11-10 14:33:54

0

如果您重新加载页面(例如使用F5键),则服务器会收到一个全新的请求,并且前一个请求的上下文丢失,因此网格视图会再次呈现其第一个页面。

但是,如果您只回发到服务器(例如通过单击提交页面的按钮),并且为网格视图启用ViewState,则应保留其当前页面。

如果你绝对要保持整个页面重新加载(而不是只回发)当前页面,你需要在一些地方仍然存在当前页面的索引,例如在用户的session state

Session["CurrentGridViewPage"] = yourGridView.PageIndex; 

,并恢复在页面加载:

if (Session["CurrentGridViewPage"] != null) { 
    yourGridView.PageIndex = (int) Session["CurrentGridViewPage"]; 
} 

编辑:如果你需要坚持的页面索引您网站上的多个页面,您需要在会话密钥一些令牌唯一标识页面,例如Request.AppRelativeCurrentExecutionFilePath

protected string PageIndexSessionKey 
{ 
    get { 
     return Request.AppRelativeCurrentExecutionFilePath + "$pgIndex"; 
    } 
} 

// Save. 
Session[PageIndexSessionKey] = yourGridView.PageIndex; 

// Restore. 
if (Session[PageIndexSessionKey] != null) { 
    yourGridView.PageIndex = (int) Session[PageIndexSessionKey]; 
} 
+0

我已经完成了。但它没有绑定到特定的页面。这是代码:protected void Refresh_Click(object sender,StoreRefreshDataEventArgs e) { Refresh(); pgtCombo.PageIndex =(int)Session [“pgIndex”]; pgtCombo.PageSize =(int)Session [“pgSize”]; Session [“pgIndex”] = string.Empty; Session [“pgSize”] = string.Empty; } – user520946 2010-11-10 07:30:46

+0

@ user490030,你是对的。这是在我更新的答案中解决的。 – 2010-11-10 16:57:39