问题
I have a telerik radgrid-control on my page for showing a list of articles. If I click a page, then an article and then back to the list again I am back at the first page instead of the one I was at before.
Is there a solution for this?
回答1:
I'm assuming you're doing a postback and things are server side...
This is a 2 step process...
First in the OnClick event for clicking on an article, put the page index into a session variable.
Second, in the RadGrid's PreRender event get the page index from that previously set session variable.
// 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();
}
}
回答2:
Do you use the Back button of the browser when you navigate back to the page with the grid? If so, you will need to use Cache or Session storage (for example) for the grid page index (CurrentPageIndex) and then restore it back.
Also make sure you use binding with NeedDataSource event or data source control.
Dick
来源:https://stackoverflow.com/questions/3086809/telerik-radgrid-doesnt-remember-page-number