GridView.PageSize Właściwość

Definicja

Pobiera lub ustawia liczbę rekordów do wyświetlenia na stronie w kontrolce GridView .

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

Wartość właściwości

Int32

Liczba rekordów do wyświetlenia na jednej stronie. Wartość domyślna to 10.

Wyjątki

Właściwość PageSize jest ustawiona na wartość mniejszą niż 1.

Przykłady

W poniższym przykładzie pokazano, jak używać PageSize właściwości do wyświetlania 15 rekordów jednocześnie w kontrolce GridView .


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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>GridView PageSize Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridView PageSize Example</h3>

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSource" 
        autogeneratecolumns="true"
        emptydatatext="No data available." 
        allowpaging="true" 
        pagesize="15"
        runat="server">
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects  -->
      <!-- to the Northwind sample database. Use an ASP.NET     -->
      <!-- expression to retrieve the connection string value   -->
      <!-- from the Web.config file.                            -->
      <asp:sqldatasource id="CustomersSource"
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>
        
    </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">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>GridView PageSize Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridView PageSize Example</h3>

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSource" 
        autogeneratecolumns="true"
        emptydatatext="No data available." 
        allowpaging="true" 
        pagesize="15"
        runat="server">
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects  -->
      <!-- to the Northwind sample database. Use an ASP.NET     -->
      <!-- expression to retrieve the connection string value   -->
      <!-- from the Web.config file.                            -->
      <asp:sqldatasource id="CustomersSource"
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>
        
    </form>
  </body>
</html>

Uwagi

Po włączeniu funkcji stronicowania (przez ustawienie AllowPaging właściwości na true), użyj PageSize właściwości , aby określić liczbę rekordów do wyświetlenia na jednej stronie.

Dotyczy

Zobacz też