Export (0) Print
Expand All

CommandField.ShowSelectButton Property

Gets or sets a value indicating whether a Select button is displayed in a CommandField field.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public virtual bool ShowSelectButton { get; set; }

Property Value

Type: System.Boolean
true to display a Select button in a CommandField; otherwise, false. The default is false.

Use the ShowSelectButton property to specify whether a Select button is displayed in a CommandField field for each record in the data-source control. The Select button allows the user to select a row in the data-source control. When the Select button for a record is clicked, the data-source control responds accordingly. For example, a GridView control updates the SelectedDataKey, SelectedIndex, SelectedRow, and SelectedValue properties to values corresponding to the selected row. The SelectedRowStyle style is then applied to the selected row and the SelectedIndexChanged and SelectedIndexChanging events are raised.

When the ButtonType property of a CommandField field is set to ButtonType.Button or ButtonType.Link, use the SelectText property to specify the text to display for a Select button. Alternatively, you can display an image by first setting the ButtonType property to ButtonType.Image and then setting the SelectImageUrl property.

The following code example demonstrates how to use the ShowSelectButton property to display a Select button for each record in a GridView control.



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



.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft