DataPager Constructor ()


Initializes a new instance of the DataPager class.

Namespace:   System.Web.UI.WebControls
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)

public DataPager()

To dynamically add a DataPager control to a page, create a new DataPager object. Set its properties, and then add it to the Controls collection of a container control, such as a PlaceHolder control.

The following example shows how to use the constructor to dynamically add a DataPager control to a page.

<%@ Page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<script runat="server">

  protected void Page_Load(object sender, EventArgs e)

    // Create a new DataPager object.
    DataPager CountryDataPager = new DataPager();

    // Set the DataPager object's properties.
    CountryDataPager.PagedControlID = CountryListView.ID;
    CountryDataPager.PageSize = 15;
    CountryDataPager.Fields.Add(new NumericPagerField());

    // Add the DataPager object to the Controls collection
    // of the form.



<html xmlns="" >
  <head id="Head1" runat="server">
    <title>DataPager Constructor Example</title>
    <form id="form1" runat="server">

      <h3>DataPager Constructor Example</h3>

      <asp:ListView ID="CountryListView" 
          <ul runat="server" id="CountryList">
            <li runat="server" id="itemPlaceholder"></li>
          <li runat="server">
            <asp:Label runat="server" ID="CountryLabel" 
              Text='<%# Eval("CountryRegionCode") + " - " + Eval("Name") %>' />

      <!-- This example uses Microsoft SQL Server and connects      -->
      <!-- to the AdventureWorks sample database. Use an ASP.NET    -->
      <!-- expression to retrieve the connection string value       -->
      <!-- from the Web.config file.                                -->
      <asp:SqlDataSource ID="CountryDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
        SelectCommand="SELECT [CountryRegionCode], [Name]
          FROM [Person].[CountryRegion]">

.NET Framework
Available since 3.5
Return to top