Home Tutorials .net framework 3.5 DataPager and ListView

Tips and tricks

Site statistics

Members : 19
Content : 104
Content View Hits : 18410

Who's Online

We have 308 guests online
DataPager and ListView PDF Print E-mail
User Rating: / 0
PoorBest 
Tutorials - .net framework 3.5
Written by dotmod   
Wednesday, 20 May 2009 02:16

Introduction to DataPager:

 
Datapager is a new control found on asp.net 3.5.  
In the asp.net 2.0 Gridview control has built-in its paging functionalities embedded within the control. 
Datapager control is a separate control on asp.net 3.5 to implement paging functionalities for asp.net databound controls. 
 
The DataPager class is used to page data and to display navigation controls for data-bound controls that implement the IPageableItemContainer interface. (An example of a control that implements the interface is the ListView control).
 

DataPager and ListView

 
Datapager can be used to create paging support for ListView control (which is also new to asp.net 3.5). Basically the DataPager control is used with the ListView control. But it can be used with any databound control that implements the IPageableItemContainer interface.  Framework provides only one control ListView that implements IPageableItemContainer till now. You can create your own control implementing IPageableItemContainer to associate with DataPager control. 
 

Using Datapager with ListView 

DataPager control can be associated with the data-bound controls by using the PagedControlID property. Alternatively, you can put the DataPager control inside the data-bound control hierarchy. For example, in the ListView control, you can put the DataPager control inside the LayoutTemplate template of ListView control. 
You can customize the number of items that are displayed for each page of data by changing the PageSize property. You can also change the way a page is submitted to the server by setting the QueryStringField property. Suppose you set the QueryStringField as “page”, and when you click on the page navigation items, you will see the on the url like [displaydata.aspx?page=4]
 
Example code: 

<asp:DataPager ID="DataPager1" PagedControlID="ListView1" PageSize="5" QueryStringField="page" runat="server">

  <Fields>

   <asp:NextPreviousPagerField ButtonType="Button"  ShowFirstPageButton="True" ShowLastPageButton="True" />

  Fields>

asp:DataPager> 
 
See the output below and also see that how the querystring is build based on the property defined on the datapage control.
 
 
This makes the possibility for users to treat as new url for each page. In contract Gridview paging uses postbak method to render new page.
 

Customizing DataPager 

 
You can customize DataPager control as per you need. You can customized the text for Navigation Buttons. You can define the css for the navigation buttons. 
 
ButtonCssClass defines the css for the navigation buttons. 
FirstPageText, LastPageText,NextPageText,PreviousPageText defines the text for navigation buttons. 
 
Example code: 
 

<asp:DataPager ID="DataPager1" PagedControlID="ListView1" PageSize="2" QueryStringField="page" runat="server">

                            <Fields>

                                <asp:NextPreviousPagerField ButtonCssClass="pagelink" FirstPageText="<<  " LastPageText="  >>" NextPageText="  >" PreviousPageText="<  "  ButtonType="Button"   ShowFirstPageButton="True"

                                    ShowLastPageButton="True" />

                            Fields>

                        asp:DataPager> 
 

Advantages of DataPager

1. Completely customizable to achieve almost all requrements regarding to paging. 
2. Supports querystring paging so that your pages can be more search engine friendly.
3. Seperate control so its more friendly in terms of page layout.
 
 
Last Updated on Friday, 18 December 2009 16:05