CommandField.ShowSelectButton Eigenschaft

Definition

Ruft einen Wert ab, der angibt, ob eine Auswählen-Schaltfläche in einem CommandField-Feld angezeigt wird, oder legt diesen fest.

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

Eigenschaftswert

true, um eine Auswählen-Schaltfläche in einem CommandField anzuzeigen, andernfalls false. Der Standardwert ist false.

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie Die ShowSelectButton -Eigenschaft verwendet wird, um eine Schaltfläche Auswählen für jeden Datensatz in einem GridView Steuerelement anzuzeigen.


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

Hinweise

Verwenden Sie die ShowSelectButton -Eigenschaft, um anzugeben, ob eine Schaltfläche Auswählen in einem CommandField Feld für jeden Datensatz im Datenquellensteuerelement angezeigt wird. Mit der Schaltfläche Auswählen kann der Benutzer eine Zeile im Datenquellensteuerelement auswählen. Wenn auf die Schaltfläche Auswählen für einen Datensatz geklickt wird, reagiert das Datenquellensteuerelement entsprechend. Beispielsweise aktualisiert ein GridView Steuerelement die SelectedDataKeyEigenschaften , SelectedIndex, SelectedRowund SelectedValue in Werte, die der ausgewählten Zeile entsprechen. Die SelectedRowStyle Formatvorlage wird dann auf die ausgewählte Zeile angewendet, und die SelectedIndexChanged Ereignisse und SelectedIndexChanging werden ausgelöst.

Wenn die ButtonType Eigenschaft eines CommandField Felds auf ButtonType.Button oder ButtonType.Linkfestgelegt ist, verwenden Sie die SelectText -Eigenschaft, um den Text anzugeben, der für eine Schaltfläche Auswählen angezeigt werden soll. Alternativ können Sie ein Bild anzeigen, indem Sie zuerst die ButtonType -Eigenschaft auf ButtonType.Image festlegen und dann die SelectImageUrl -Eigenschaft festlegen.

Gilt für:

Weitere Informationen