Last post Nov 07, 2010 09:58 PM by Qin Dian Tang - MSFT
Nov 03, 2010 06:26 AM|cseven|LINK
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">
<%# Container.StartRowIndex + 1 %> to
<%# ((Container.StartRowIndex + Container.PageSize) > Container.TotalRowCount ? Container.TotalRowCount : (Container.StartRowIndex + Container.PageSize)) %>
of <%# Container.TotalRowCount %> records
<asp:NumericPagerField ButtonCount="7" />
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?
Nov 05, 2010 03:49 AM|Qin Dian Tang - MSFT|LINK
Here are some good articles about creating pager template of DataPger:
Nov 05, 2010 02:19 PM|cseven|LINK
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 shared, and the last one only shows how to create a user control
that will be used as the custom PagerTemplate of the DataPager control.
What I'm trying to do is something close to the last link, but I want to dynamically create the whole DataPager Control from a Server Control.
I know how to create a simple DataPager from code, I just don't know how to create the custom PagerTemplate and associate it to the DataPager.
How can I create an ITemplate with 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 type variable?
What I want is to recreate the code in the first post (that was done in design mode) dynamically in a C# class, for a Server Control.
Nov 07, 2010 09:58 PM|Qin Dian Tang - MSFT|LINK
The controls in PagerTemplate can be accessed in the DataPager1.Controls. You can add anything to it. Do you mean this?