This is a migrated thread and some comments may be shown as answers.

Set StartIndex

2 Answers 52 Views
DataPager
This is a migrated thread and some comments may be shown as answers.
Jens-Thomas
Top achievements
Rank 1
Jens-Thomas asked on 14 Aug 2014, 12:55 PM
Hi,

I'm calling a page containing a data pager. Part of my initial call url is a page number I would like to go to.
I searched around and tried a lot of things without success:
- FireCommand
- SEO Paging

What is the designed way to specify a start page for a data pager?

THANKS!

2 Answers, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 19 Aug 2014, 11:07 AM
Hi Jens,

I have already provided an answer in the official support ticket you have opened regarding this matter. In order to avoid duplicate posts I would kindly like to ask you to post your queries there. Later you can share your findings here so other community members can benefit from them.

Regards,
Angel Petrov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Jens-Thomas
Top achievements
Rank 1
answered on 25 Aug 2014, 03:22 PM
I finally solved it! It turned out to be quite tricky as I had some dependencies on the current page that where not satisfied when using FireCommand - it was simply to late when fired.

So the correct approach and only way to set the initial start page, is to use FireCommand within OnPreRenderComplete:
protected override void OnPreRenderComplete(EventArgs e)
    {
        base.OnPreRenderComplete(e);
        if (!IsPostBack)
        {
            RadDataPager1.FireCommand("Page", "5");
        }
    }

In case OnPreRenderComplete is to late - i.e. data bindings on some other controls that would need the current page, it would be important to decouple it from RadDataPager.CurrentPageIndex and set a global variable for it. So you have the page either from the URL or in case of a post back the pager control itself.

Here some code:

int pageIndex = 0;
 
protected void Page_Init(object sender, EventArgs e)
{
    .....
     
    // set current page from URL - PART I
    if (!IsPostBack && string.IsNullOrEmpty(Request["p"]))
    {
        try
        {
            pageIndex = int.Parse(Request["p"]);
        }
        catch
        {          
        }
    }
 
    .....
 
}
 
protected override void OnLoad(EventArgs e)
{
    // get current page from control
    if (IsPostBack)
    {
        pageIndex = RadDataPager1.CurrentPageIndex;
    }
}
 
protected override void OnPreRenderComplete(EventArgs e)
{
    base.OnPreRenderComplete(e);
 
    // set current page from URL - PART II
    if (!IsPostBack && string.IsNullOrEmpty(Request["p"]))
    {
        RadDataPager1.FireCommand("Page", pageIndex.ToString());
    }
}
 
protected void RadDataPager1_PageIndexChanged(object sender, RadDataPagerPageIndexChangeEventArgs e)
{
 
    // when changing the page using the control in the page, get current(new) page from the event
    // OnLoad contains the OLD value
    if (IsPostBack)
    {
        pageIndex = e.NewPageIndex;
         
        // re data bind dependent controls for new page
        RadListView1.DataBind();
    }
}
 
protected void RadListView1_OnDataBinding(object sender, EventArgs args)
{
    ...
                 
    // use pageIndex for current page
 
    ...
}

Hope this helps...

Thanks to Telerik for clarification of the RadDataPager behavior and the idea with the global variable.

Jens
Tags
DataPager
Asked by
Jens-Thomas
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Jens-Thomas
Top achievements
Rank 1
Share this question
or