Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

How to: Enable Default Selection in the GridView Web Server Control

The ASP.NET GridView control has a built-in selection capability that allows users to select a row in the grid. Selecting a row in a GridView control does not inherently perform any task. However, by adding selection capability, you can add functionality to the grid that relies on users pointing to a specific row. Typical uses for adding selection capability to the GridView control include:

  • When users select a row, the row is redisplayed with a different look.

  • When users select a row, related data is displayed elsewhere in the page, such as in a DetailsView control.

Procedures

To enable selection using the smart tag

  1. In Design view, right-click the GridView control and click Show Smart Tag.

  2. In the smart tag panel, select Enable Selection.

To enable default selection using the AutoGenerateSelectButton property

  • Select the GridView control, and in the Properties window, set AutoGenerateSelectButton to true.

    -or-

  • In Source view, in the <asp:GridView> element, set the AutoGenerateSelecttButton attribute to true:

    <asp:GridView Runat="server" ID="GridView1" 
      AutoGenerateSelectButton="true" />
    

To customize the look of a row in selection mode

  • Set properties for the SelectedRowStyle.

    For example, if you set the BackColor subproperty of the SelectedRowStyle to gray, a selected row is displayed with a gray background.

To customize the command text of the Select button

  1. Select the GridView control, and in the Properties window, click the ellipsis (...) button in the Columns box.

    The Fields dialog box is displayed.

  2. Under Selected fields, click Select.

  3. Under CommandField properties, in the SelectText box, enter text for the Select button.

To change the command text of the Select button to an image

  1. Select the GridView control, and in the Properties window, click the ellipsis (...) button in the Columns box.

    The Fields dialog box is displayed.

  2. Under Selected fields, click Select.

  3. Under CommandField properties, in the SelectImageUrl box, enter or select the URL of the image to use for the Select button.

See Also

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft