2010-06-21 68 views
0

我有一个telerik radgrid控件在我的页面上显示文章列表。如果我点击一个页面,然后是一篇文章,然后又回到列表,我回到了第一页,而不是之前的页面。Telerik radgrid不记得页码

有没有解决方案呢?

回答

4

我假设你正在做一个回传,事情是服务器端...

这是一个两个步骤...

首先在onclick事件点击文章,将页面索引放入会话变量中。

其次,在RadGrid的PreRender事件中,从先前设置的会话变量中获取页面索引。

// Set the page index, call this on your OnClick event 
private void SetRadGridPageIndex(int PageIndex) 
{ 
    Session["RadGridCurrentPageIndex"] = PageIndex; 
} 

// Get the page index, call this on RadGrid's PreRender event 
// Don't forget to Rebind the RadGrid 
private void GetRadGridPageIndex() 
{ 
    // Go to the previously selected page 
    if (Session["RadGridCurrentPageIndex"] != null) 
    { 
     this.RadGrid1.CurrentPageIndex = Convert.ToInt32(Session["RadGridCurrentPageIndex"]); 
     this.RadGrid1.MasterTableView.Rebind(); 
    } 
} 
+0

答案是非常非常好,它确实需要什么,只是一点点另外的完整性,执行时PageRender时,如果在真实的案例,加上这样的事情后:会话[“RadGridCurrentPageIndex”] = null;或者当你在跳转到PageIndex的时候,你会在PageIndex中设置session的值,然后你就不再需要这个值了。 – 2014-05-06 23:26:48

0

当您使用网格导航回页面时,是否使用浏览器的“后退”按钮?如果是这样,则需要为网格页面索引(CurrentPageIndex)使用缓存或会话存储(例如),然后将其恢复。

另外请确保您使用与NeedDataSource事件或数据源控件的绑定。

迪克