CommandField.ShowSelectButton Propriété

Définition

Obtient ou définit une valeur indiquant si un bouton Sélectionner est affiché dans un champ CommandField.

public:
 virtual property bool ShowSelectButton { bool get(); void set(bool value); };
public virtual bool ShowSelectButton { get; set; }
member this.ShowSelectButton : bool with get, set
Public Overridable Property ShowSelectButton As Boolean

Valeur de propriété

true pour afficher un bouton Sélectionner dans un CommandField ; sinon, false. La valeur par défaut est false.

Exemples

L’exemple de code suivant montre comment utiliser la ShowSelectButton propriété pour afficher un bouton Sélectionner pour chaque enregistrement d’un GridView contrôle.


<%@ 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 CustomersGridView_SelectedIndexChanged(Object sender, EventArgs e)
  {
    // Retrieve the company name from the appropriate cell.
    String companyName = CustomersGridView.SelectedRow.Cells[2].Text;
   
    // Display company name selected by the user.
    Message.Text = "You selected " + companyName + ".";
  }
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>CommandField Example</title>
</head>
<body>
    <form id="form1" runat="server">
      
      <h3>CommandField Example</h3>
      
      <asp:Label id="Message"
        forecolor="Red"
        runat="server"/>

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="false"
        datakeynames="CustomerID"
        onselectedindexchanged="CustomersGridView_SelectedIndexChanged"   
        runat="server">
        
        <columns>
          <asp:commandfield showselectbutton="true"
            headertext="Select Customer"/>
          <asp:boundfield datafield="CustomerID"
            headertext="Customer ID" />
          <asp:boundfield datafield="CompanyName"
            headertext="Company Name"/>
          <asp:boundfield datafield="Address"
            headertext="Address"/>
          <asp:boundfield datafield="City"
            headertext="City"/>
          <asp:boundfield datafield="PostalCode"
            headertext="ZIP Code"/>
          <asp:boundfield datafield="Country"
            headertext="Country"/>
        </columns>
        
      </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>

<%@ 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">
  
  Sub CustomersGridView_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles CustomersGridView.SelectedIndexChanged
 
    ' Retrieve the company name from the appropriate cell.
    Dim companyName As String = CustomersGridView.SelectedRow.Cells(2).Text
   
    ' Display company name selected by the user.
    Message.Text = "You selected " & companyName & "."
    
  End Sub
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>CommandField Example</title>
</head>
<body>
    <form id="form1" runat="server">
      
      <h3>CommandField Example</h3>
      
      <asp:Label id="Message"
        forecolor="Red"
        runat="server"/>

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="false"
        datakeynames="CustomerID"  
        runat="server">
        
        <columns>
          <asp:commandfield showselectbutton="true"
            headertext="Select Customer"/>
          <asp:boundfield datafield="CustomerID"
            headertext="Customer ID" />
          <asp:boundfield datafield="CompanyName"
            headertext="Company Name"/>
          <asp:boundfield datafield="Address"
            headertext="Address"/>
          <asp:boundfield datafield="City"
            headertext="City"/>
          <asp:boundfield datafield="PostalCode"
            headertext="ZIP Code"/>
          <asp:boundfield datafield="Country"
            headertext="Country"/>
        </columns>
        
      </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>

Remarques

Utilisez la ShowSelectButton propriété pour spécifier si un bouton Sélectionner s’affiche dans un CommandField champ pour chaque enregistrement dans le contrôle de source de données. Le bouton Sélectionner permet à l’utilisateur de sélectionner une ligne dans le contrôle de source de données. Lorsque vous cliquez sur le bouton Sélectionner d’un enregistrement, le contrôle de source de données répond en conséquence. Par exemple, un GridView contrôle met à jour les SelectedDataKeypropriétés , SelectedIndex, SelectedRowet SelectedValue en valeurs correspondant à la ligne sélectionnée. Le SelectedRowStyle style est ensuite appliqué à la ligne sélectionnée et les SelectedIndexChanged événements et SelectedIndexChanging sont déclenchés.

Lorsque la ButtonType propriété d’un CommandField champ a la ButtonType.Button valeur ou ButtonType.Link, utilisez la SelectText propriété pour spécifier le texte à afficher pour un bouton Sélectionner. Vous pouvez également afficher une image en définissant d’abord la ButtonType propriété sur ButtonType.Image , puis en définissant la SelectImageUrl propriété.

S’applique à

Voir aussi