Cet article a fait l'objet d'une traduction manuelle. Déplacez votre pointeur sur les phrases de l'article pour voir la version originale de ce texte. |
Traduction
Source
|
ButtonType, énumération
Spécifie les différents types de boutons pouvant être affichés dans une page Web Forms.
Assembly : System.Web (dans System.Web.dll)
L'énumération ButtonType est utilisée pour représenter les différents types de boutons (boutons de commande, boutons d'image, boutons de lien, etc.) pouvant être affichés sur une page ASP.NET. Celle-ci est couramment utilisée par les propriétés telles que la propriété ButtonType de la classe ButtonFieldBase pour indiquer le type de bouton utilisé par le contrôle parent.
L'exemple suivant montre comment utiliser l'énumération ButtonType pour spécifier que les boutons de lien sont affichés dans une colonne de champ ButtonField d'un contrôle GridView. ButtonType.Link est affecté de manière déclarative à la propriété ButtonType d'un objet ButtonField.
<%@ 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 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 xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>ButtonType Example</title> </head> <body> <form id="form1" runat="server"> <h3>ButtonType Example</h3> <asp:label id="Message" forecolor="Red" runat="server" AssociatedControlID="AuthorsGridView"/> <!-- 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 7, Windows Vista SP1 ou ultérieur, Windows XP SP3, Windows XP SP2 Édition x64, Windows Server 2008 (installation minimale non prise en charge), Windows Server 2008 R2 (installation minimale prise en charge avec SP1 ou version ultérieure), Windows Server 2003 SP2
Le .NET Framework ne prend pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.