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

RadDatapager Template - Set defaults

4 Answers 115 Views
DataPager
This is a migrated thread and some comments may be shown as answers.
Angie
Top achievements
Rank 1
Angie asked on 15 Nov 2012, 09:32 PM
Hello, I use a the RadDataPager in multiple places throughout my project.  I have many properties set in a specific fashion, and I find myself having to copy/paste the pager all over.

Is there a way to set up a skin or a default style or a control for the pager so that the options can be set in one place only?

Below is my code for the pager.  I even end up duplicating it on each single page due to the fact that I show the pager on the top and on the bottom of the page.

Thanks!
<telerik:RadDataPager ID="RadDataPagerBottom" runat="server" IsTotalItemCountFixed="True" Skin="Windows7" Width="730px" CssClass="Custom">
        <Fields>
             <telerik:RadDataPagerButtonField FieldType="FirstPrev" />
              <telerik:RadDataPagerButtonField FieldType="Numeric" />
              <telerik:RadDataPagerButtonField FieldType="NextLast" />
               <telerik:RadDataPagerTemplatePageField HorizontalPosition="RightFloat">
               <PagerTemplate>
               <div style="float: right;color:#666666;">
                Displaying items <asp:Label runat="server" ID="CurrentPageLabel" Text="<%# Container.Owner.StartRowIndex + 1 %>" />
 to 
<asp:Label runat="server" ID="TotalPagesLabel" Text="<%# (Container.Owner.TotalRowCount < Container.Owner.StartRowIndex + Container.Owner.PageSize)?Container.Owner.TotalRowCount:Container.Owner.StartRowIndex + Container.Owner.PageSize  %>" />
                                                of
    <asp:Label runat="server" ID="TotalItemsLabel" Text="<%# Container.Owner.TotalRowCount %>" />
                                        </div>
                                    </PagerTemplate>
                                </telerik:RadDataPagerTemplatePageField>
                            </Fields>        
                         </telerik:RadDataPager>

4 Answers, 1 is accepted

Sort by
0
Angie
Top achievements
Rank 1
answered on 19 Nov 2012, 05:24 PM
Ok, so I've figured out how to use the skin file to default the buttons and their placement.

Now I need to figure out if it is possible to extend the RadDataPager so that I can perform some default c# operations:  setting the "Display Items x of y" labels, setting the page size programmatically, and handling the hiding of the pager when there are just a few records.
Thanks!

Skin file code:
<telerik:RadDataPager runat="server" Skin="Windows7" >
    <Fields>
    <telerik:RadDataPagerTemplatePageField HorizontalPosition="LeftFloat">
        <PagerTemplate>
            <div style="float: right;color:#666666;">
                Displaying items
                    <asp:Label runat="server" ID="CurrentPageLabel"  />
                    to
                    <asp:Label runat="server" ID="TotalPagesLabel"  />
                    of
                    <asp:Label runat="server" ID="TotalItemsLabel"  />
                    
            </div>
        </PagerTemplate>
    </telerik:RadDataPagerTemplatePageField>
     <telerik:RadDataPagerButtonField FieldType="NextLast" HorizontalPosition="RightFloat" />
      <telerik:RadDataPagerButtonField FieldType="Numeric" HorizontalPosition="RightFloat" />
    <telerik:RadDataPagerButtonField FieldType="FirstPrev" HorizontalPosition="RightFloat" />
     
    </Fields>        
</telerik:RadDataPager>

Code behind functions I would like to handle:
protected void lvCEResults_DataBound(object sender, EventArgs e)
    {
        RadDataPager pagerTop = (RadDataPager)lvCEResults.FindControl("RadDataPagerTop");
        pagerTop.PageSize = int.Parse(ConfigurationManager.AppSettings["RESULTS_PAGE_SIZE"].ToString());
        pagerTop.Visible = !(totalRecordCount <= lvCEResults.PageSize);
 
        RadDataPager pagerBottom = (RadDataPager)lvCEResults.FindControl("RadDataPagerBottom");
        pagerBottom.PageSize = int.Parse(ConfigurationManager.AppSettings["RESULTS_PAGE_SIZE"].ToString());
        pagerBottom.Visible = !(totalRecordCount <= lvCEResults.PageSize);
    }

0
Andrey
Telerik team
answered on 20 Nov 2012, 12:31 PM
Hi,

In the Skin files you could set only visual properties, there is no code-behind as you most probably already knows.

The best solution in your case would be to use application settings defined in the Web.config file. Then you could find the DataPager control and apply those settings. You could check this MSDN thread for more information on how you could read application settings from Web.Config file.

Kind regards,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Angie
Top achievements
Rank 1
answered on 20 Nov 2012, 04:08 PM
Hi Andrey, thanks for your reply.  I am using the web config for static variables, such as page size, but for variables that change (total records, page number, etc), it doesn't make sense to use the web config.  Luckily, I've figured out how to extend the telerik pager class, so that I can do the work I need to do in one area, rather than having to copy and paste the same code everywhere.

I'll include the code here for others that may have the same question.

So, I am using the skin file for the styling of the pager, which I've changed to reflect the name of my extended control.
<CCWeb:TelerikPager runat="server" Skin="Windows7" IsTotalItemCountFixed="True" >
    <Fields>
    <telerik:RadDataPagerTemplatePageField HorizontalPosition="LeftFloat">
        <PagerTemplate>
            <div style="float: right;color:#666666;">
                Displaying items
                    <asp:Label runat="server" ID="PageItemFromLabel"  />
                    to
                    <asp:Label runat="server" ID="PageItemToLabel"  />
                    of
                    <asp:Label runat="server" ID="TotalItemsLabel"  />
            </div>
        </PagerTemplate>
    </telerik:RadDataPagerTemplatePageField>
     <telerik:RadDataPagerButtonField FieldType="NextLast" HorizontalPosition="RightFloat" />
      <telerik:RadDataPagerButtonField FieldType="Numeric" HorizontalPosition="RightFloat" />
    <telerik:RadDataPagerButtonField FieldType="FirstPrev" HorizontalPosition="RightFloat" />
    </Fields>        
</CCWeb:TelerikPager>


And then here is the c# code I'm using to extend the pager itself.  (A class file in the app_code folder.)
public class TelerikPager : RadDataPager
    {
        protected override void  OnInit(EventArgs e)
        {
            PageSize = int.Parse(ConfigurationManager.AppSettings["RESULTS_PAGE_SIZE"].ToString());
            base.OnInit(e);
        }
 
        protected override void OnPreRender(EventArgs e)
        {
           ((Label)this.Controls[0].FindControl("PageItemFromLabel")).Text = (StartRowIndex + 1).ToString();
           ((Label)this.Controls[0].FindControl("PageItemToLabel")).Text = ((TotalRowCount < (StartRowIndex + PageSize)) ? TotalRowCount : StartRowIndex + PageSize).ToString();
           ((Label)this.Controls[0].FindControl("TotalItemsLabel")).Text = TotalRowCount.ToString();
             
            if (TotalRowCount <= PageSize)
                this.Visible = false;
 
            base.OnPreRender(e);
        }
    }

Hope that may help someone.
0
Andrey
Telerik team
answered on 21 Nov 2012, 01:24 PM
Hello,

Yes, this is one possible approach for your case. Than you for providing this information for the community.

Kind regards,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
DataPager
Asked by
Angie
Top achievements
Rank 1
Answers by
Angie
Top achievements
Rank 1
Andrey
Telerik team
Share this question
or