.netpaginationtelerik

Telerik radgrid doesn't remember page number


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?


Solution

  • 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();
        }
    }