Controls You Can Use on Web Forms ASP.NET Data Controls DataGrid Control
A ButtonColumn in a DataGrid 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 ButtonColumn, an author can include custom-defined buttons, such as an "Add to shopping cart" button.
A ButtonColumn can have one of the following button types:
Button Type |
Description |
LinkButton |
Renders a column of link buttons. |
PushButton |
Renders a column of push buttons. |
The button captions can either be static text or text read from a database.
- Set the DataGrid 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 ButtonColumn is clicked ( in effect, when the DataGrid's ItemCommand event occurs ).
<asp:datagrid id="myGrid" runat="server"
autogeneratecolumns=false
...
onItemCommand="updateCart"
>
- Within the DataGrid declaration, declare a <Columns> element.
- Within the Columns element, define each of the <
asp:ButtonColumn
> 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 ).
- Optionally set the ButtonColumn control’s other properties. For syntax, see DataGrid Control Syntax.
The following examples show several ways of using a ButtonColumn to display a column of command buttons in a DataGrid control.
For additional information, see ButtonColumn in the class library.
Adding Bound Columns to a DataGrid Control Adding Hyperlink Columns to a DataGrid Control Adding Template Columns to a DataGrid Control