다음을 통해 공유


DataPager 생성자

정의

DataPager 클래스의 새 인스턴스를 초기화합니다.

public:
 DataPager();
public DataPager ();
Public Sub New ()

예제

다음 예제에서는 생성자를 사용 하 여 동적으로 추가 하는 방법을 보여 줍니다는 DataPager 컨트롤 페이지입니다.

<%@ Page language="C#" %>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

  // <Snippet2>
  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.
    form1.Controls.Add(CountryDataPager);

    CountryListView.DataBind();
  }
  // </Snippet2>
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head id="Head1" runat="server">
    <title>DataPager Constructor Example</title>
  </head>
  <body>
    <form id="form1" runat="server">
      
      <h3>DataPager Constructor Example</h3>

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

      <!-- 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]">
      </asp:SqlDataSource>
    </form>
  </body>
</html>
<%@ Page language="VB" %>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

  ' <Snippet2>  
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    
    ' Create a new DataPager object.
    Dim CountryDataPager As 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.
    form1.Controls.Add(CountryDataPager)

    CountryListView.DataBind()
    
  End Sub
  ' </Snippet2>
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head id="Head1" runat="server">
    <title>DataPager Constructor Example</title>
  </head>
  <body>
    <form id="form1" runat="server">
      
      <h3>DataPager Constructor Example</h3>

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

      <!-- 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]">
      </asp:SqlDataSource>
    </form>
  </body>
</html>

설명

동적으로 추가 하는 DataPager 컨트롤을 페이지, 새 DataPager 개체입니다. 해당 속성을 설정한 다음에 추가 하는 Controls 등의 컬렉션 컨테이너 컨트롤을 PlaceHolder 컨트롤입니다.

적용 대상

추가 정보