Export (0) Print
Expand All

ButtonColumn Class

A column type for the DataGrid control that contains a user-defined button.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public class ButtonColumn : DataGridColumn
public class ButtonColumn extends DataGridColumn
public class ButtonColumn extends DataGridColumn

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.HeaderText="Add Item"; 
   AddColumn.Text="Add";
   AddColumn.CommandName="Add";
   AddColumn.ButtonType = ButtonColumnType.PushButton;


   // Add column to Columns collection.
   ItemsGrid.Columns.AddAt(2, AddColumn);

}
   

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);

}
   

System.Object
   System.Web.UI.WebControls.DataGridColumn
    System.Web.UI.WebControls.ButtonColumn

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft