This documentation is archived and is not being maintained.

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"
<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 + ".";


<html xmlns="" >
  <head runat="server">
    <title>CommandField Example</title>
    <form id="form1" runat="server">

      <h3>CommandField Example</h3>

      <asp:Label id="Message"

      <asp:gridview id="CustomersGridView" 

          <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"
          <asp:boundfield datafield="City"
          <asp:boundfield datafield="PostalCode"
            headertext="ZIP Code"/>
          <asp:boundfield datafield="Country"


      <!-- 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%>"


.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.