Datapager and Gridview
Why datapager with gridview
DataListView already supports datpager in asp.net 3.5 and everything you want you can get from the datalistview. Still why to use datapager with gridview. Gridview doesnot supports datapager bydefault. You have to extend gridview implementing IPageableContainer.
If you are migrating from old asp.net 2.0 to asp.net 3.5 and you have used gridview in lots of pages. In the process of migration from asp.net 2.0 to 3.5 you might want to use datapager as your page navigation elements, but you want the existing gridivew as the data display control, extending the gridview is an option.
Why use Datapager:
Gridview by default supports paging and sorting so why you want datapager. There is one disadvantage of inline paging of gridview over datapager.
1. Datapager paging navigation elements can be completely customized. You cant put navigation elements at the top of the grid. With datapager you can put where ever you like since it is a separate independent control.
2. Gridview uses postback method for paging as datapager can be configured to use querystring parameter. The makes possible to create url links to directly go to a specified page.
You can download the custom control (extended from gridview) which supports datapager below
How to use:
1. Register the control on the page level or on applicaiton level(web.config)
<%@ Register Assembly="CustomControls" Namespace="CustomControls" TagPrefix="cc1" %>
2. Place the gridview on the datapager and bind with object datasource
<cc1:gridviewext datasourceid="ObjectDataSource1" autogeneratecolumns="False" allowpaging="true" runat="server" id="GridViewExt1"> <columns> <asp:boundfield sortexpression="UserId" headertext="UserId" datafield="UserId"></asp:boundfield> <asp:boundfield sortexpression="UserName" headertext="UserName" datafield="UserName"></asp:boundfield> </columns> </cc1:gridviewext> <asp:objectdatasource selectcountmethod="CountUsers" typename="DataProvider" selectmethod="GetUsers" enablepaging="true" runat="server" id="ObjectDataSource1"> </asp:objectdatasource>
3. Place datapager control on the page and configure it to use with the above gridview.
<asp:datapager pagedcontrolid="GridViewExt1" querystringfield="user" runat="server" pagesize="10" id="DataPager1"> <fields> <asp:templatepagerfield> Page <%# Container.TotalRowCount>0 ? (Container.StartRowIndex / Container.PageSize) + 1 : 0 %> of <%# Math.Ceiling ((double)Container.TotalRowCount / Container.PageSize) %> (<%# Container.TotalRowCount%> records) </pagertemplate> </asp:templatepagerfield> <asp:nextpreviouspagerfield showpreviouspagebutton="True" shownextpagebutton="false" showfirstpagebutton="true"></asp:nextpreviouspagerfield> <asp:numericpagerfield buttoncount="5" nextpagetext="Next 10 >" previouspagetext="< Prev 10"></asp:numericpagerfield> <asp:nextpreviouspagerfield shownextpagebutton="True" showlastpagebutton="true" showpreviouspagebutton="false"></asp:nextpreviouspagerfield> </fields> </asp:datapager>






