asp.net.ph

GridView.AutoGenerateSelectButton Property

System.Web.UI.WebControls Namespace   GridView Class


.NET Framework version 2.0

Sets or retrieves a value specifying whether a CommandField column with a Select button for each data row is automatically added and displayed in a GridView control.

Syntax


Inline <asp:gridview autogenerateselectbutton = true | false ... >
Script GridView.AutoGenerateSelectButton [ = true | false ]

Property Value

This property accepts or returns only a boolean value: true if a CommandField column with a Select button for each data row is automatically added and displayed; otherwise, false. Default value is false.

Remarks

Use this property to automatically create a CommandField column with a Select button for each data row in a GridView control.

Clicking the Select button for a row sets the SelectedIndex property to the index of the row, and also sets a reference to the selected GridViewRow object via the SelectedRow property.

Note that for the automatic selection feature to work, the DataKeyNames property must be set to specify the key field or fields of the data source that will identify the record to select.

Optionally, the DataKeyNames property can be set to specify the key field or fields in the data source that uniquely identifies the record bound to each row. This provides a convenient way to access the GridView's SelectedValue property, which would contain the value(s) of the key field(s) when the Select button for a row is clicked.

The GridView control raises the following events to which you can assign a custom action to perform when a row is selected.

Event Description
SelectedIndexChanging Occurs when a row's Select button is clicked, but before the GridView control handles the select operation. This event is often used to cancel the selection operation.
SelectedIndexChanged Occurs when a row's Select button is clicked, but after the GridView control handles the select operation. This event is often used to perform a task after a row is selected in the control.

Example

The below snippet demonstrates how to use the AutoGenerateSelectButton property to enable the automatic selection feature of a GridView control.

<asp:gridview id = "empsGrid" runat="server"
   datasourceid = "employees"
   datakeynames = "employeeID"
   autogenerateselectbutton
   autogeneratecolumns=false
   cellpadding=5 font-size=8pt
   selectedrowstyle-backcolor = "khaki">
GridView AutoGenerateSelectButton Example
Run Sample | View Source
See Also

GridView Members   AutoGenerateDeleteButton   AutoGenerateEditButton   Allowing Users to Select Rows in a GridView Control Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph