Blue Theme Orange Theme Green Theme Red Theme
 
Home | Forums | Videos | Photos | Downloads | Blogs | E-Books | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Login Close
User Id:
Password:
 
Forgot Password
Forgot Username
Why Register
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
 Resources  
Close
 Our Network  
Close
Search :       Advanced Search »
Home » ASP.NET & Web Forms » DataPager in ASP.NET 3.5

DataPager in ASP.NET 3.5

The ListView is a hybrid control between a DataGrid and Repeater that combines the templating of the Repeater and the editing features of the data grid, but doesn't support paging, so the DataPager serves as an external control to provide paging features.

Author Rank:
Technologies: ASP.NET 3.5, Controls,Visual C# .NET
Total downloads : 234
Total page views :  7653
Rating :
 5/5
This article has been rated :  1 times
   Print Read/Post comments Post a comment  Rate  
   Email to a friend  Bookmark  Similar Articles  Author's other articles  
Download Files:
DataPager.zip
 
Become a Sponsor


Related EbooksTop Videos

The ListView is a hybrid control between a DataGrid and Repeater that combines the templating of the Repeater and the editing features of the data grid. The ListView is similar to the Repeater in that it allows one to define the layout of the HTML rendered to the browser, using various templates:

  1. LayoutTemplate - The root template that defines a container object, such as a table, div, or span element, that will contain the content defined in the ItemTemplate or GroupTemplate template. It might also contain a DataPager object.
  2.  ItemTemplate - Defines the data-bound content to display for individual items.
  3. ItemSeparatorTemplate - Defines the content to render between individual items.
  4. GroupTemplate - Defines a container object, such as a table row (tr), div, or span element, that will contain the content defined in the ItemTemplate and EmptyItemTemplate templates. The number of items that are displayed in a group is specified by the GroupItemCount property.
  5. GroupSeparatorTemplate - Defines the content to render between groups of items.
  6. EmptyItemTemplate - Defines the content to render for an empty item when a GroupTemplate template is used. For example, if the GroupItemCount property is set to 5, and the total number of items returned from the data source is 8, the last group of data displayed by the ListView control will contain three items as specified by the ItemTemplate template, and two items as specified by the EmptyItemTemplate template.
  7. EmptyDataTemplate - Defines the content to render if the data source returns no data.
  8. SelectedItemTemplate - Defines the content to render for the selected data item to differentiate the selected item from other items.
  9. AlternatingItemTemplate - Defines the content to render for alternating items to make it easier to distinguish between consecutive items.
  10. EditItemTemplate - Defines the content to render when an item is being edited. The EditItemTemplate template is rendered in place of the ItemTemplate template for the data item that is being edited.
  11. InsertItemTemplate - Defines the content to render to insert an item. The InsertItemTemplate template is rendered in place of an ItemTemplate template at either the start or at the end of the items that are displayed by the ListView control. You can specify where the InsertItemTemplate template is rendered by using the InsertItemPosition property of the ListView control.

The ListView doesn't support paging, so the DataPager serves as an external control to provide paging features. The advantage of a separate control is that it gives more control about what the pager looks like and where it can be placed on the page. The DataPager class is used to page data and to display navigation controls for data-bound controls that implement the IPageableItemContainer interface.

 DataPager control can be associated with the data-bound control by using the PagedControlID property. Alternatively, by putting the DataPager control inside the data-bound control hierarchy. For example, in the ListView control, DataPager control can be kept inside the ListView-LayoutTemplate.

The number of items that are displayed for each page of data can be customized by changing the PageSize property. The way a page is submitted to the server can be changed by setting the QueryStringField property.

Pager Fields

In order for the DataPager control to display navigation controls, pager fields are added to the control that are derived from the DataPagerField class.

Pager field type

Description

NextPreviousPagerField

Enables users to navigate through pages one page at a time, or to jump to the first or last page.

NumericPagerField

Enables users to select a page by page number.

TemplatePagerField

Enables you to create a custom paging UI.


To declaratively add pager fields to the DataPager control, add a Fields element to the DataPager control. You can then add the pager fields to the Fields element. The pager fields are added to the Fields collection in the order that they appear in the Fields element. The Fields collection enables you to programmatically manage the pager fields in the DataPager control.

Page Properties

The following table lists read-only properties of the DataPager control that specify characteristics of the page of data. These properties are usually used for binding expressions in the TemplatePagerField object.

Property

Description

MaximumRows

The maximum number of records that are displayed for each page of data.

StartRowIndex

The index of the first record that is displayed on a page of data.

TotalRowCount

The total number of records that are available in the underlying data source.


Let us create a small example using the Northwind database.

Create the Layout Template that will represent that how ListView will look

<LayoutTemplate>

<table class="tableInfo">

          <tr>

              <th width="250">

                 Product Name

              </th>

              <th width="150">

                  Quantity/Unit

              </th>

              <th width="100">

                  Unit Price

              </th>

           </tr>

      <asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder>

           <tr>

             <td colspan="3" align="center"><%--<asp:DataPager here>--%>

             </td>

           </tr>

      </table>

</LayoutTemplate>

Create a ListView with ItemTemplate containing the fields that you want to show from Products table


<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" ItemPlaceholderID="itemPlaceHolder">

<ItemTemplate>
      <
tr>

          <td>

              <%# Eval("ProductName") %>

          </td>

          <td>

              <%# Eval("QuantityPerUnit") %>

          </td>

          <td>

              <%# Eval("UnitPrice","{0:c}") %>

          </td>

      </tr>

      </ItemTemplate>

</asp:ListView>

Put the DataPager inside the ListView Layout Template or anywhere on that page. Here I am putting the DataPager inside the Layout Template

 

<asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1" PageSize="10" class="NavegationBar">

   <Fields>

       <asp:NextPreviousPagerField ButtonType="Image" FirstPageImageUrl="~/Images/Paging/FirstHover.gif"         ShowFirstPageButton="true" PreviousPageImageUrl="~/Images/Paging/PreviousHover.gif"   ShowLastPageButton="false" ShowNextPageButton="false" />

        <asp:NumericPagerField ButtonCount="5" />

        <asp:NextPreviousPagerField ButtonType="Image" ShowLastPageButton="true" ShowNextPageButton="true"

                                                ShowPreviousPageButton="false" LastPageImageUrl="~/Images/Paging/LastHover.gif" NextPageImageUrl="~/Images/Paging/NextHover.gif" />

   </Fields>

</asp:DataPager>

 

 

 


Login to add your contents and source code to this article
 [Top] Rate this article
 About the author
 
Nipun Tomar
Nipun has 5 years working experience in .NET technologies. He holds Bachelor's and Master's degree in Computer Science. Currently working on ASP.NET 2.0/3.5, VB.NET, C#.NET, AJAX, SQL Server 2005, WPF, WCF and Silverlight.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Go.NET
Build custom interactive diagrams, network, workflow editors, flowcharts, or software design tools. Includes many predefined kinds of nodes, links, and basic shapes. Supports layers, scrolling, zooming, selection, drag-and-drop, clipboard, in-place editing, tooltips, grids, printing, overview window, palette. 100% implemented in C# as a managed .NET Control. Document/View/Tool architecture with many properties&events. Optional automatic layout.
Dundas Software
Dundas Chart for .NET is the most advanced .NET charting package available today.  With an extremely complete feature set, elegant architecture and easy implementation, Dundas Chart can quickly add advanced Charting functionality to enhance and transform ASP.NET and Windows Forms applications.  Whether you are implementing charting into internal projects, or building applications for clients, Dundas Chart offers advanced technology and advanced results to get the most out of data.
Clickatell's SMS Gateway
Clickatell's Developer Solutions allow you to SMS enable any website or application via a range of API's. Learn More about our API connections.
Free access to .NET Memory Management video
Everything you need to know about Garbage Collection, Temporary Objects, Fragmentation, Finalization and common causes of memory leaks in .NET. Watch the video here.
Microsoft Visual Studio 2010
Microsoft Visual Studio 2010 offers more to developers than any other Visual Studio release. Work more productively and collaboratively-with greater control over your work at every step. The Beta 2 can give you a head start on achieving efficiency.
 
   Print Read/Post comments Post a comment  Rate  
   Email to a friend  Bookmark  Similar Articles  Author's other articles  
Download Files:
DataPager.zip
 
 Post a Feedback, Comment, or Question about this article
Subject:  
Comment:  
Become a Sponsor
 Comments

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Suggest an Idea  |  Media Kit
Current Version: 5.2009.6.2
 © 1999 - 2009  Mindcracker LLC. All Rights Reserved