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)

[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class ButtonColumn : 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);

}

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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft