Espandi Riduci a icona
Questo argomento non è stato ancora valutato - Valuta questo argomento

Enumerazione ButtonType

Nota: questa enumerazione è stata introdotta con .NET Framework versione 2.0.

Specifica i diversi tipi di pulsanti di cui è possibile eseguire il rendering in una pagina Web Form.

Spazio dei nomi: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public enum ButtonType
public enum ButtonType
public enum ButtonType
 Nome membroDescrizione
ButtonUn pulsante di comando. 
ImageUn pulsante che visualizza un'immagine. 
LinkUn pulsante con lo stile di un collegamento ipertestuale. 

Per rappresentare i diversi tipi di pulsanti di cui è possibile eseguire il rendering in una pagina ASP.NET, ad esempio i pulsanti di comando, i pulsanti immagine, i pulsanti di collegamento e così via, viene utilizzata l'enumerazione ButtonType. Questa enumerazione viene comunemente utilizzata dalle proprietà, tra cui la proprietà ButtonType della classe ButtonFieldBase, per indicare il tipo di pulsante utilizzato dal controllo padre.

Nell'esempio riportato di seguito viene illustrato come utilizzare l'enumerazione ButtonType per specificare che i pulsanti di collegamento vengono visualizzati in una colonna associata a campo ButtonField di un controllo GridView. La proprietà ButtonType di un oggetto ButtonField viene impostata in modo dichiarativo su ButtonType.Link.


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

<script runat="server">

  void AuthorsGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
  {
  
    // If multiple ButtonField column fields are used, use the
    // CommandName property to determine which button was clicked.
    if(e.CommandName=="Select")
    {
    
      // Convert the row index stored in the CommandArgument
      // property to an Integer.
      int index = Convert.ToInt32(e.CommandArgument);    
    
      // Get the last name of the selected author from the appropriate
      // cell in the GridView control.
      GridViewRow selectedRow = AuthorsGridView.Rows[index];
      TableCell lastNameCell = selectedRow.Cells[1];
      string lastName = lastNameCell.Text;  
    
      // Display the selected author.
      Message.Text = "You selected " + lastName + ".";
      
    }
    
  }
  
  void AuthorsGridView_RowCreated(Object sender, GridViewRowEventArgs e)
  {
    
    // The GridViewCommandEventArgs class does not contain a 
    // property that indicates which row's command button was
    // clicked. To identify which row contains the button 
    // clicked, use the button's CommandArgument property by 
    // setting it to the row's index.
    if(e.Row.RowType == DataControlRowType.DataRow)
    {
    
      // Retrieve the button control from the first column.
      // Because the ButtonType property of the column field
      // is set to ButtonType.Link, the button control must be
      // cast to a LinkButton. If you specify a different button
      // type, you must cast the button control to the appropriate
      // button type.
      LinkButton selectButton = (LinkButton)e.Row.Cells[0].Controls[0];
            
      // Set the LinkButton's CommandArgument property with the
      // row's index.
      selectButton.CommandArgument = e.Row.RowIndex.ToString();
      
    }

  }
    
</script>

<html>
  <body>
    <form runat="server">
        
      <h3>ButtonType Example</h3>
      
      <asp:label id="Message"
        forecolor="Red"
        runat="server"/>
                    
      <!-- Populate the Fields collection declaratively. -->
      <asp:gridview id="AuthorsGridView" 
        datasourceid="AuthorsSqlDataSource" 
        autogeneratecolumns="false"
        onrowcommand="AuthorsGridView_RowCommand" 
        runat="server">
                
        <columns>
                
          <asp:buttonfield buttontype="Link" commandname="Select" text="Select"/>
          <asp:boundfield datafield="au_lname" headertext="au_lname"/>
          <asp:boundfield datafield="au_fname" headertext="au_fname"/>
                
        </columns>
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Pubs sample database.                        -->
      <asp:sqldatasource id="AuthorsSqlDataSource"  
        selectcommand="SELECT [au_lname], [au_fname] FROM [authors]"
        connectionstring="server=localhost;database=pubs;integrated security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework non supporta tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema.

.NET Framework

Supportato in: 2.0
Il documento è risultato utile?
(1500 caratteri rimanenti)

Aggiunte alla community

AGGIUNGI
© 2013 Microsoft. Tutti i diritti riservati.