ButtonColumn Class
Assembly: System.Web (in system.web.dll)
Use the ButtonColumn class in a DataGrid control to create a button that corresponds with each row in the DataGrid control. Specify the caption that is displayed in the buttons by setting the Text property. If you set the Text property, all buttons in the ButtonColumn object share the same caption. Alternatively, you can bind the ButtonColumn buttons to a field in a data source. This allows you to display different captions for each button. The values in the specified field are used for the text caption. Set the DataTextField property to bind the ButtonColumn to a field in a data source.
You can format the captions that are displayed in the buttons by setting the DataTextField property with a formatting string.
Clicking the buttons in the ButtonColumn raises the ItemCommand event. You can programmatically control the action that is performed when the button is clicked by providing an event handler for the ItemCommand event.
By default, page validation is not performed when a button in the ButtonColumn is clicked. Page validation determines whether the input controls that are associated with a validation control on the page all pass the validation rules that are specified by the validation control. To perform page validation when a button is clicked, set the CausesValidation property to true.
The following code example demonstrates how to use ButtonColumn class in a DataGrid control to create Add buttons.
private void Page_Init(Object sender, EventArgs e)
{
// Create dynamic column to add to Columns collection.
ButtonColumn addColumn = new ButtonColumn();
addColumn.set_HeaderText("Add Item");
addColumn.set_Text("Add");
addColumn.set_CommandName("Add");
addColumn.set_ButtonType(ButtonColumnType.PushButton);
// Add column to Columns collection.
itemsGrid.get_Columns().AddAt(2, addColumn);
} //Page_Init
private function Page_Init(sender : Object, e : EventArgs) { // Create dynamic column to add to Columns collection. var AddColumn : ButtonColumn = new ButtonColumn(); AddColumn.HeaderText="Add Item"; AddColumn.Text="Add"; AddColumn.CommandName="Add"; AddColumn.ButtonType = ButtonColumnType.PushButton; // Add column to Columns collection. ItemsGrid.Columns.AddAt(2, AddColumn); }