Home » Asp.netRSS

DataPager Control in a Server Control

Hi.


I'm trying to create a Server Control that will use a DataPager Control, but I'm having some difficulties with the PagerTemplate.

This is the DataPager control that I want to generate from a Server Control:


    <asp:DataPager ID="myPager" PageSize="20" runat="server">
        <Fields>
            <asp:TemplatePagerField>
                <PagerTemplate>
                    <div class="counter">
                        <%# Container.StartRowIndex + 1 %> to 
                        <%# ((Container.StartRowIndex + Container.PageSize) > Container.TotalRowCount ? Container.TotalRowCount : (Container.StartRowIndex + Container.PageSize))  %>
                        of <%# Container.TotalRowCount %> records
                    </div>
                </PagerTemplate>
            </asp:TemplatePagerField>
            <asp:NextPreviousPagerField ButtonType="link"
                    FirstPageText="first"  
                    ShowFirstPageButton="true"
                    ShowNextPageButton="false"
                    ShowPreviousPageButton="false"
                    RenderDisabledButtonsAsLabels="true" />
            <asp:NumericPagerField ButtonCount="7" />
            <asp:NextPreviousPagerField ButtonType="link"
                        LastPageText="last"
                        ShowLastPageButton="true"
                        ShowNextPageButton="false"
                        ShowPreviousPageButton="false" />
        </Fields>
    </asp:DataPager>


I don't know how to create the PagerTemplate from code. I'm stuck in a part where I need to create a ITemplate, but I don't know how to work with it.

I've done some search but haven't found anything that could help me. I'm a bit newbie with Server Controls. I can do some simple ones, but templates are new to me.

Can anyone give me some help on this?


Thanks Laughing

 

2 Answers Found

 
 

Answer 2

Hi Qin Dian Tang,


Thanks for the answer but those links don't respond to my question. The first two only show how to create a DataPager from design mode, and I already have that as you can see from the code I've pasted, and the last one shows how to create a use control that will be used as a PagerTemplate of a DataPager control.

What I'm trying to do is something close to that last link, but I want to create a Server Control wich will render dynamically and completely a DataPager control.

I know how to create a DataPager from code, I just don't know how to create the custom PagerTemplate and associate it to the PagerControl.

How can I create an ITemplate with other controls or HTML like this:

 <div class="counter">                        <%# Container.StartRowIndex + 1 %> to                         <%# ((Container.StartRowIndex + Container.PageSize) > Container.TotalRowCount ? Container.TotalRowCount : (Container.StartRowIndex + Container.PageSize))  %>                        of <%# Container.TotalRowCount %> records                    </div>


And then associate this ITemplate to the DataPager control variable.


What I want is to recreate the code on the first post, that was done in design mode, dynamically in a C# class, for a Server Control.


Thanks. 



 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter