Controls You Can Use on Web Forms ASP.NET Data Controls GridView Control
A ButtonField in a GridView control enables authors to define custom functionality for items in the grid beyond the select, edit, delete, and hyperlink features of other column types. Using the ButtonField, an author can include custom-defined buttons, such as an "Add to shopping cart" button.
A ButtonField can have one of the following button types:
Button Type |
Description |
Link |
Renders a column of link buttons. |
Button |
Renders a column of push buttons. |
Image |
Renders a column of buttons with images. |
The button captions can either be static text or text read from a database.
- Set the GridView control’s AutoGenerateColumns property to false.
- Optionally assign the handler ( if there is one ) that will receive control when any of the buttons in the ButtonField is clicked ( in effect, when the GridView's RowCommand event occurs ).
<asp:GridView id="myGrid" runat="server"
autogeneratecolumns=false
...
onRowCommand="updateCart"
>
- Within the GridView declaration, declare a <Columns> element.
- Within the Columns element, define each of the <
asp:ButtonField
> controls you intend to display, specifying at the very least the following:
- the ButtonType property ( optional for link buttons, required for push and image buttons ).
- the CommandName for each button ( required for all button types ).
- the Text or DataTextField property ( required for link or push buttons ).
- the ImageUrl property ( required for image buttons ).
- Optionally set the ButtonField control’s other properties. For syntax, see GridView Control Syntax.
The following examples show several ways of using a ButtonField to display a column of command buttons in a GridView control.
For additional information, see ButtonField in the class library.
Adding Bound Fields to a GridView Control Adding Hyperlink Fields to a GridView Control Adding Template Fields to a GridView Control