다음을 통해 공유


DataPager.PageSize 속성

정의

각 데이터 페이지에 표시되는 레코드 수를 가져오거나 설정합니다.

public:
 property int PageSize { int get(); void set(int value); };
public int PageSize { get; set; }
member this.PageSize : int with get, set
Public Property PageSize As Integer

속성 값

각 데이터 페이지에 표시되는 레코드 수입니다. 기본값은 10입니다.

예외

PageSize 속성이 1보다 작은 값으로 설정된 경우

예제

다음 예제에서는 선언적으로 설정 하는 방법을 보여 줍니다 합니다 PageSize 속성에는 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">

  protected void ResultsList_SelectedIndexChanged(object sender, EventArgs e)
  {
    // Set the page size with the value
    // selected in the DropDownList object
    VendorsDataPager.PageSize = Convert.ToInt32(ResultsList.SelectedValue);
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head id="Head1" runat="server">
    <title>DataPager PageSize Example</title>
</head>
<body>
    <form id="form1" runat="server">
      
      <h3>DataPager PageSize Example</h3>
      
      <table border="0" width="640px">
        <tr>
          <td align="left">
            <asp:Label id="ResultsLabel" runat="server" 
              AssociatedControlID="ResultsList" Text="Results per page:" />            
            <asp:DropDownList runat="server" id="ResultsList" 
              OnSelectedIndexChanged="ResultsList_SelectedIndexChanged" AutoPostBack="true">              
              <asp:ListItem Value="10"  />
              <asp:ListItem Value="15" Selected="True" />
              <asp:ListItem Value="20" />
            </asp:DropDownList>
          </td>
          <td align="right">
            <asp:DataPager ID="VendorsDataPager" runat="server" 
              PagedControlID="VendorsListView" PageSize="15">
              <Fields>
                <asp:NumericPagerField />
              </Fields>
            </asp:DataPager>          
          </td>
        </tr>
      </table>
      <br />
      
      <asp:ListView ID="VendorsListView" 
        DataSourceID="VendorsDataSource"
        runat="server">
        <LayoutTemplate>
          <table cellpadding="2" width="640px">
              <tr runat="server" id="itemPlaceholder"></tr>
          </table>
        </LayoutTemplate>
        <ItemTemplate>
          <tr runat="server">
            <td>
              <asp:Label ID="VendorIDLabel" runat="server" Text='<%# Eval("VendorID") %>' />
            </td>
            <td>
              <asp:Label ID="AccountNumberLabel" runat="server" Text='<%# Eval("AccountNumber") %>' />
            </td>
            <td>
              <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
            </td>
            <td align="center">
              <asp:CheckBox ID="PreferredCheckBox" runat="server" 
                Checked='<%# Eval("PreferredVendorStatus") %>' Enabled="False" />
            </td>
          </tr>
        </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="VendorsDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"            
        SelectCommand="SELECT VendorID, AccountNumber, Name, PreferredVendorStatus 
          FROM Purchasing.Vendor WHERE (ActiveFlag = 1)" >
      </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">

  Protected Sub ResultsList_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) 

    ' Set the page size with the value
    ' selected in the DropDownList object  
    VendorsDataPager.PageSize = Convert.ToInt32(ResultsList.SelectedValue)
    
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head id="Head1" runat="server">
    <title>DataPager PageSize Example</title>
</head>
<body>
    <form id="form1" runat="server">
      
      <h3>DataPager PageSize Example</h3>
      
      <table border="0" width="640px">
        <tr>
          <td align="left">
            <asp:Label id="ResultsLabel" runat="server" 
              AssociatedControlID="ResultsList" Text="Results per page:" />            
            <asp:DropDownList runat="server" id="ResultsList" 
              OnSelectedIndexChanged="ResultsList_SelectedIndexChanged" AutoPostBack="true">              
              <asp:ListItem Value="10"  />
              <asp:ListItem Value="15" Selected="True" />
              <asp:ListItem Value="20" />
            </asp:DropDownList>
          </td>
          <td align="right">
            <asp:DataPager ID="VendorsDataPager" runat="server" 
              PagedControlID="VendorsListView" PageSize="15">
              <Fields>
                <asp:NumericPagerField />
              </Fields>
            </asp:DataPager>          
          </td>
        </tr>
      </table>
      <br />
      
      <asp:ListView ID="VendorsListView" 
        DataSourceID="VendorsDataSource"
        runat="server">
        <LayoutTemplate>
          <table cellpadding="2" width="640px">
              <tr runat="server" id="itemPlaceholder"></tr>
          </table>
        </LayoutTemplate>
        <ItemTemplate>
          <tr runat="server">
            <td>
              <asp:Label ID="VendorIDLabel" runat="server" Text='<%# Eval("VendorID") %>' />
            </td>
            <td>
              <asp:Label ID="AccountNumberLabel" runat="server" Text='<%# Eval("AccountNumber") %>' />
            </td>
            <td>
              <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
            </td>
            <td align="center">
              <asp:CheckBox ID="PreferredCheckBox" runat="server" 
                Checked='<%# Eval("PreferredVendorStatus") %>' Enabled="False" />
            </td>
          </tr>
        </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="VendorsDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"            
        SelectCommand="SELECT VendorID, AccountNumber, Name, PreferredVendorStatus 
          FROM Purchasing.Vendor WHERE (ActiveFlag = 1)" >
      </asp:SqlDataSource>
    </form>
  </body>
</html>

설명

사용 된 PageSize 속성을 데이터 페이지의 크기를 지정 합니다.

여러 개인 경우 DataPager 동일 하 게 바인딩된 페이지에 컨트롤 ListView 컨트롤을 설정 해야 합니다 PageSize 동일한 값으로 이러한 컨트롤의 속성입니다. 경우는 DataPager 컨트롤은 서로 다른 페이지 크기, 마지막 사용 하도록 설정 DataPager 초기화 될 컨트롤의 실제 페이지 크기를 결정 합니다 ListView 컨트롤입니다.

적용 대상

추가 정보