GridView.PageSize Proprietà

Definizione

Ottiene o imposta il numero di record da visualizzare in una pagina di un controllo 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

Valore della proprietà

Int32

Il numero di record da visualizzare in una singola pagina. Il valore predefinito è 10.

Eccezioni

La proprietà PageSize è impostata su un valore minore di 1.

Esempio

Nell'esempio seguente viene illustrato come utilizzare la PageSize proprietà per visualizzare 15 record alla volta in un GridView controllo .


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

Commenti

Quando la funzionalità di paging è abilitata (impostando la AllowPaging proprietà su true), utilizzare la PageSize proprietà per specificare il numero di record da visualizzare in una singola pagina.

Si applica a

Vedi anche