GridView.PagerTemplate (Propiedad)
Ensamblado: System.Web (en system.web.dll)
[TemplateContainerAttribute(typeof(GridViewRow))] public virtual ITemplate PagerTemplate { get; set; }
/** @property */ public ITemplate get_PagerTemplate () /** @property */ public void set_PagerTemplate (ITemplate value)
public function get PagerTemplate () : ITemplate public function set PagerTemplate (value : ITemplate)
Valor de propiedad
System.Web.UI.ITemplate con el contenido personalizado de la fila de paginación. El valor predeterminado es null, lo que indica que no se ha establecido esta propiedad.Una fila de paginación se muestra en un control GridView cuando se habilita la característica de paginación (cuando la propiedad AllowPaging se establece en true). La fila de paginación contiene los controles que permiten al usuario desplazarse a las distintas páginas del control. En lugar de utilizar la interfaz de usuario (UI) de fila de paginación integrada, puede definir su propia UI mediante la propiedad PagerTemplate.
Nota: |
|---|
| Cuando se establece la propiedad PagerTemplate, reemplaza la UI de fila de paginación integrada. |
Si desea especificar una plantilla personalizada para la fila de paginación, primero coloque las etiquetas <PagerTemplate> entre las etiquetas de apertura y cierre del control GridView. A continuación, incluya el contenido de la plantilla entre las etiquetas <PagerTemplate> de apertura y cierre. Para controlar la apariencia de la fila de paginación, utilice la propiedad PagerStyle.
Normalmente se agregan a la plantilla de paginación controles de botón para realizar las operaciones de paginación. El control GridView realiza una operación de paginación cuando se hace clic en un control de botón con la propiedad CommandName establecida en "Page". La propiedad CommandArgument del botón determina el tipo de operación de paginación que se va a realizar. En la siguiente tabla se enumeran los valores de argumentos de comando admitidos por el control GridView.
| Valor CommandArgument | Descripción |
|---|---|
| "Next" | Se desplaza a la página siguiente. |
| "Prev" | Se desplaza a la página anterior. |
| "First" | Se desplaza a la primera página. |
| "Last" | Se desplaza a la última página. |
| Valor entero | Se desplaza al número de página especificado. |
En el ejemplo de código siguiente se muestra cómo crear una plantilla de paginación personalizada que permite al usuario desplazarse por un control GridView utilizando un control DropDownList.
<%@ 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"> void PageDropDownList_SelectedIndexChanged(Object sender, EventArgs e) { // Retrieve the pager row. GridViewRow pagerRow = CustomersGridView.BottomPagerRow; // Retrieve the PageDropDownList DropDownList from the bottom pager row. DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList"); // Set the PageIndex property to display that page selected by the user. CustomersGridView.PageIndex = pageList.SelectedIndex; } void CustomersGridView_DataBound(Object sender, EventArgs e) { // Retrieve the pager row. GridViewRow pagerRow = CustomersGridView.BottomPagerRow; // Retrieve the DropDownList and Label controls from the row. DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList"); Label pageLabel = (Label)pagerRow.Cells[0].FindControl("CurrentPageLabel"); if(pageList != null) { // Create the values for the DropDownList control based on // the total number of pages required to display the data // source. for(int i=0; i<CustomersGridView.PageCount; i++) { // Create a ListItem object to represent a page. int pageNumber = i + 1; ListItem item = new ListItem(pageNumber.ToString()); // If the ListItem object matches the currently selected // page, flag the ListItem object as being selected. Because // the DropDownList control is recreated each time the pager // row gets created, this will persist the selected item in // the DropDownList control. if(i==CustomersGridView.PageIndex) { item.Selected = true; } // Add the ListItem object to the Items collection of the // DropDownList. pageList.Items.Add(item); } } if(pageLabel != null) { // Calculate the current page number. int currentPage = CustomersGridView.PageIndex + 1; // Update the Label control with the current page information. pageLabel.Text = "Page " + currentPage.ToString() + " of " + CustomersGridView.PageCount.ToString(); } } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>GridView PagerTemplate Example</title> </head> <body> <form id="form1" runat="server"> <h3>GridView PagerTemplate Example</h3> <asp:gridview id="CustomersGridView" datasourceid="CustomersSqlDataSource" autogeneratecolumns="true" allowpaging="true" ondatabound="CustomersGridView_DataBound" runat="server"> <pagerstyle forecolor="Blue" backcolor="LightBlue"/> <pagertemplate> <table width="100%"> <tr> <td style="width:70%"> <asp:label id="MessageLabel" forecolor="Blue" text="Select a page:" runat="server"/> <asp:dropdownlist id="PageDropDownList" autopostback="true" onselectedindexchanged="PageDropDownList_SelectedIndexChanged" runat="server"/> </td> <td style="width:70%; text-align:right"> <asp:label id="CurrentPageLabel" forecolor="Blue" runat="server"/> </td> </tr> </table> </pagertemplate> </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="CustomersSqlDataSource" selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"> </asp:sqldatasource> </form> </body> </html>
Windows 98, Windows 2000 Service Pack 4, Windows CE, Windows Millennium, Windows Mobile para Pocket PC, Windows Mobile para Smartphone, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter
Microsoft .NET Framework 3.0 es compatible con Windows Vista, Microsoft Windows XP SP2 y Windows Server 2003 SP1.Referencia
GridView (Clase)GridView (Miembros)
System.Web.UI.WebControls (Espacio de nombres)
System.Web.UI.ITemplate
GridView.PagerStyle (Propiedad)
GridView.PagerSettings (Propiedad)
GridView.PageCount (Propiedad)
GridView.PageIndex (Propiedad)
GridView.BottomPagerRow (Propiedad)
TopPagerRow
GridView.EmptyDataTemplate (Propiedad)
PageIndexChanged
PageIndexChanging
Nota: