DataPagerCommandEventArgs DataPagerCommandEventArgs DataPagerCommandEventArgs DataPagerCommandEventArgs Class

Definizione

Fornisce i dati per l'evento PagerCommand della classe TemplatePagerField.Provides data for the PagerCommand event of the TemplatePagerField class.

public ref class DataPagerCommandEventArgs : System::Web::UI::WebControls::CommandEventArgs
public class DataPagerCommandEventArgs : System.Web.UI.WebControls.CommandEventArgs
type DataPagerCommandEventArgs = class
    inherit CommandEventArgs
Public Class DataPagerCommandEventArgs
Inherits CommandEventArgs
Ereditarietà
DataPagerCommandEventArgsDataPagerCommandEventArgsDataPagerCommandEventArgsDataPagerCommandEventArgs

Esempi

Nell'esempio seguente viene illustrato come utilizzare l' DataPagerCommandEventArgs oggetto per consentire all'utente di specificare quale pagina di dati verrà visualizzata ListView nel controllo.The following example shows how to use the DataPagerCommandEventArgs object to enable the user to specify which page of data will be displayed in the ListView control. L' DataPagerCommandEventArgs oggetto viene passato al gestore per l' PagerCommand evento della TemplatePagerField classe.The DataPagerCommandEventArgs object is passed to the handler for the PagerCommand event of the TemplatePagerField class.

Importante

Questo esempio contiene una casella di testo che accetta l'input dell'utente, che rappresenta una potenziale minaccia per la sicurezza.This example contains a text box that accepts user input, which is a potential security threat. Per impostazione predefinita, le pagine Web ASP.NET verificano che l'input dell'utente non includa script o elementi HTML.By default, ASP.NET Web pages validate that user input does not include script or HTML elements. Per altre informazioni, vedere Cenni preliminari sugli attacchi tramite script.For more information, see Script Exploits Overview.

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

  // <Snippet2>
  protected void TemplatePagerField_OnPagerCommand(object sender, DataPagerCommandEventArgs e)
  {     
      // Get the new page number 
      TextBox PageNumberTextBox = (TextBox)e.Item.FindControl("PageNumberTextBox");
      int newPageNumber = -1;
      try
      {
        newPageNumber = Convert.ToInt32(PageNumberTextBox.Text.Trim());
      }
      catch (FormatException)
      {
        Message.Text = "Invalid page number.";
        return;
      }
      catch (OverflowException)
      {
        Message.Text = "Invalid page number.";
        return;
      }

      int newIndex = (newPageNumber - 1) * e.Item.Pager.PageSize;
      //Verify if the new index is valid
      if (newIndex >= 0 && newIndex <= e.TotalRowCount)
      {
        //Set the new start index and maximum rows
        e.NewStartRowIndex = newIndex;
        e.NewMaximumRows = e.Item.Pager.MaximumRows;
      }
      else
        Message.Text = "Invalid page number.";
  }
  // </Snippet2>

  protected void Page_Load(object sender, EventArgs e)
  {
    Message.Text = "";
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head id="Head1" runat="server">
    <title>DataPagerCommandEventArgs Example</title>    
    <style type="text/css">
      body 	
      {
      	text-align: center;
      	font: 12px Arial, Helvetica, sans-serif;
      }
      .item
      {
          border: 1px solid #8b7e66;
          background: white;
          min-height: 19px;
          width: 33%;
      }
      .alternatingItem
      {
        border: solid 1px #8b7e66;
        background: #f5deb3;
        width: 33%;
        min-height: 19px;
      }      
    </style>
  </head>
  <body>
    <form id="form1" runat="server">
        
    <h3>DataPagerCommandEventArgs Example</h3>

      <asp:ListView ID="ContactsListView" 
        DataSourceID="ContactsDataSource"
        GroupItemCount="3"
        runat="server">
        <LayoutTemplate>
          <table cellpadding="4" width="640px" id="tblProducts" runat="server">
            <tr runat="server" id="groupPlaceholder" />
          </table>
          <asp:DataPager runat="server" 
            ID="ContactsDataPager" 
            PageSize="30"
            PagedControlID="ContactsListView">
            <Fields>
              <asp:TemplatePagerField OnPagerCommand="TemplatePagerField_OnPagerCommand">
                <PagerTemplate>
                  <b>
                  Page
                  <asp:Label runat="server" ID="CurrentPageLabel" 
                    Text="<%# Container.TotalRowCount>0 ? (Container.StartRowIndex / Container.PageSize) + 1 : 0 %>" />
                  of
                  <asp:Label runat="server" ID="TotalPagesLabel" 
                    Text="<%# Math.Ceiling ((double)Container.TotalRowCount / Container.PageSize) %>" />
                  </b>              
                  <br /><br />
                  Jump to page:
                  <asp:TextBox ID="PageNumberTextBox" runat="server" 
                    Width="30px" 
                    Text="<%# Container.TotalRowCount>0 ? (Container.StartRowIndex / Container.PageSize) + 1 : 0 %>" />                      
                  <asp:Button ID="GoButton" runat="server" Text="Go" />
                  <br /><br />
                </PagerTemplate>
              </asp:TemplatePagerField>
            </Fields>
          </asp:DataPager>
        </LayoutTemplate>
        <GroupTemplate>
          <tr runat="server" id="ProductsRow">
            <td runat="server" id="itemPlaceholder" />
          </tr>
        </GroupTemplate>
        <ItemTemplate>
          <td class="item" runat="server">
            <asp:Label ID="NameLabel" runat="server" 
              Text='<%# Eval("LastName") + ", " + Eval("FirstName")%>' />
          </td>
        </ItemTemplate>
        <AlternatingItemTemplate>
          <td class="alternatingItem" runat="server">
            <asp:Label ID="NameLabel" runat="server" 
              Text='<%# Eval("LastName") + ", " + Eval("FirstName")%>' />
          </td>
        </AlternatingItemTemplate>
      </asp:ListView>
      <br />      

      <asp:Label ID="Message"
        ForeColor="Red"
        runat="server"/>

      <!-- 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="ContactsDataSource" runat="server" 
            ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
            SelectCommand="SELECT [ContactID], [FirstName], [LastName] 
              FROM Person.Contact">
      </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">

  '<Snippet2>  
  Protected Sub TemplatePagerField_OnPagerCommand(ByVal sender As Object, _
    ByVal e As DataPagerCommandEventArgs)
    
    ' Get the new page number 
    Dim PageNumberTextBox As TextBox = _
      CType(e.Item.FindControl("PageNumberTextBox"), TextBox)
    
    Dim newPageNumber As Integer = -1
    Try
      newPageNumber = Convert.ToInt32(PageNumberTextBox.Text.Trim())
    Catch fex As FormatException
      Message.Text = "Invalid page number."
      Return
    Catch oex As OverflowException
      Message.Text = "Invalid page number."
      Return
    End Try
        
    Dim newIndex As Integer = _
      (newPageNumber - 1) * e.Item.Pager.PageSize
    
    'Verify if the new index is valid
    If newIndex >= 0 AndAlso newIndex <= e.TotalRowCount Then
      'Set the new start index and maximum rows
      e.NewStartRowIndex = newIndex
      e.NewMaximumRows = e.Item.Pager.MaximumRows
    Else
      Message.Text = "Invalid page number."
    End If
    
  End Sub
  ' </Snippet2>
     
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    Message.Text = ""
  End Sub
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head id="Head1" runat="server">
    <title>DataPagerCommandEventArgs Example</title>    
    <style type="text/css">
      body 	
      {
      	text-align: center;
      	font: 12px Arial, Helvetica, sans-serif;
      }
      .item
      {
          border: 1px solid #8b7e66;
          background: white;
          min-height: 19px;
          width: 33%;
      }
      .alternatingItem
      {
        border: solid 1px #8b7e66;
        background: #f5deb3;
        width: 33%;
        min-height: 19px;
      }      
    </style>
  </head>
  <body>
    <form id="form1" runat="server">
        
    <h3>DataPagerCommandEventArgs Example</h3>

      <asp:ListView ID="ContactsListView" 
        DataSourceID="ContactsDataSource"
        GroupItemCount="3"
        runat="server">
        <LayoutTemplate>
          <table cellpadding="4" width="640px" id="tblProducts" runat="server">
            <tr runat="server" id="groupPlaceholder" />
          </table>
          <asp:DataPager runat="server" 
            ID="ContactsDataPager" 
            PageSize="30"
            PagedControlID="ContactsListView">
            <Fields>
              <asp:TemplatePagerField OnPagerCommand="TemplatePagerField_OnPagerCommand">
                <PagerTemplate>
                  <b>
                  Page
                  <asp:Label runat="server" ID="CurrentPageLabel" 
                    Text="<%# IIf(Container.TotalRowCount>0, (Container.StartRowIndex / Container.PageSize) + 1 , 0) %>" />
                  of
                  <asp:Label runat="server" ID="TotalPagesLabel" 
                    Text="<%# Math.Ceiling (System.Convert.ToDouble(Container.TotalRowCount / Container.PageSize)) %>" />
                  </b>              
                  <br /><br />
                  Jump to page:
                  <asp:TextBox ID="PageNumberTextBox" runat="server" 
                    Width="30px" 
                    Text="<%# IIf(Container.TotalRowCount>0, (Container.StartRowIndex / Container.PageSize) + 1, 0) %>" />
                  <asp:Button ID="GoButton" runat="server" Text="Go" />
                  <br /><br />
                </PagerTemplate>
              </asp:TemplatePagerField>
            </Fields>
          </asp:DataPager>
        </LayoutTemplate>
        <GroupTemplate>
          <tr runat="server" id="ProductsRow">
            <td runat="server" id="itemPlaceholder" />
          </tr>
        </GroupTemplate>
        <ItemTemplate>
          <td id="Td1" class="item" runat="server">
            <asp:Label ID="NameLabel" runat="server" 
              Text='<%# Eval("LastName") & ", " & Eval("FirstName")%>' />
          </td>
        </ItemTemplate>
        <AlternatingItemTemplate>
          <td id="Td2" class="alternatingItem" runat="server">
            <asp:Label ID="NameLabel" runat="server" 
              Text='<%# Eval("LastName") & ", " & Eval("FirstName")%>' />
          </td>
        </AlternatingItemTemplate>
      </asp:ListView>
      <br />

      <asp:Label ID="Message"
        ForeColor="Red"
        runat="server"/>

      <!-- 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="ContactsDataSource" runat="server" 
            ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
            SelectCommand="SELECT [ContactID], [FirstName], [LastName] 
              FROM Person.Contact">
      </asp:SqlDataSource>
      
    </form>
  </body>
</html>

Commenti

L' TemplatePagerField oggetto genera l' PagerCommand evento quando si Buttonfa clic su ImageButton un controllo, LinkButtono all'interno del campo del pager.The TemplatePagerField object raises the PagerCommand event when a Button, LinkButton, or ImageButton control that is inside the pager field is clicked. Questi pulsanti sono controlli figlio che possono essere definiti nel PagerTemplate modello di un TemplatePagerField campo.These buttons are child controls that can be defined in the PagerTemplate template of a TemplatePagerField field.

Durante l'evento, è possibile eseguire attività quali la modifica del numero di righe che verranno visualizzate o la modifica dell'indice del primo elemento nella pagina.During the event, you can perform tasks such as changing the number of rows that will be displayed or changing the index of the first item on the page.

Per altre informazioni su come gestire gli eventi, vedere la gestione e generazione di eventi.For more information about how to handle events, see Handling and Raising Events.

Per un elenco dei valori iniziali delle proprietà di un'istanza della classe DataPagerCommandEventArgs, vedere il costruttore DataPagerCommandEventArgs.For a list of initial property values for an instance of the DataPagerCommandEventArgs class, see the DataPagerCommandEventArgs constructor.

Costruttori

DataPagerCommandEventArgs(DataPagerField, Int32, CommandEventArgs, DataPagerFieldItem) DataPagerCommandEventArgs(DataPagerField, Int32, CommandEventArgs, DataPagerFieldItem) DataPagerCommandEventArgs(DataPagerField, Int32, CommandEventArgs, DataPagerFieldItem) DataPagerCommandEventArgs(DataPagerField, Int32, CommandEventArgs, DataPagerFieldItem)

Inizializza una nuova istanza della classe DataPagerCommandEventArgs.Initializes a new instance of the DataPagerCommandEventArgs class.

Proprietà

CommandArgument CommandArgument CommandArgument CommandArgument

Ottiene l'argomento del comando.Gets the argument for the command.

(Inherited from CommandEventArgs)
CommandName CommandName CommandName CommandName

Ottiene il nome del comando.Gets the name of the command.

(Inherited from CommandEventArgs)
Item Item Item Item

Ottiene l'oggetto DataPagerFieldItem che include l'oggetto DataPagerField e l'oggetto DataPagerField del contenitore dell'oggetto DataPager.Gets the DataPagerFieldItem object that contains the DataPagerField object and the DataPagerField object's container DataPager object.

NewMaximumRows NewMaximumRows NewMaximumRows NewMaximumRows

Ottiene o imposta il numero massimo di record da visualizzare in ogni pagina di dati.Gets or sets the maximum number of records to display on each page of data.

NewStartRowIndex NewStartRowIndex NewStartRowIndex NewStartRowIndex

Ottiene o imposta l'indice del primo record da visualizzare in una pagina di dati.Gets or sets the index of the first record to display on a page of data.

PagerField PagerField PagerField PagerField

Ottiene l'oggetto DataPagerField contenente il pulsante su cui è stato fatto clic.Gets the DataPagerField object that contains the button that was clicked.

TotalRowCount TotalRowCount TotalRowCount TotalRowCount

Ottiene il numero totale di record da visualizzare.Gets the total number of records to display.

Metodi

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Funge da funzione hash predefinita.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Ottiene l'oggetto Type dell'istanza corrente.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.Returns a string that represents the current object.

(Inherited from Object)

Si applica a

Vedi anche