Sdílet prostřednictvím


GridView.PageSize Vlastnost

Definice

Získá nebo nastaví počet záznamů, které se mají zobrazit na stránce v ovládacím GridView prvku.

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

Hodnota vlastnosti

Int32

Počet záznamů, které se mají zobrazit na jedné stránce. Výchozí hodnota je 10.

Výjimky

Vlastnost PageSize je nastavena na hodnotu menší než 1.

Příklady

Následující příklad ukazuje, jak použít PageSize vlastnost k zobrazení 15 záznamů najednou v ovládacím GridView prvku.


<%@ 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>

Poznámky

Pokud je funkce stránkování povolená (nastavením AllowPaging vlastnosti truena ), použijte PageSize vlastnost k určení počtu záznamů, které se mají zobrazit na jedné stránce.

Platí pro

Viz také