asp.net.ph

ButtonField Class

System.Web.UI.WebControls Namespace


.NET Framework version 2.0

Represents a field that is displayed as a button in a data-bound control.

ButtonField Class Members

Collapse   Constructors

Visibility Constructor Parameters
public ButtonField ( )

Collapse   Properties

Visibility Name Value Type Accessibility
public CommandName String [ Get , Set ]
public DataTextField String [ Get , Set ]
public DataTextFormatString String [ Get , Set ]
public ImageUrl String [ Get , Set ]
public Text String [ Get , Set ]

Collapse   Methods

Visibility Name Parameters Return Type
protected CopyProperties ( DataControlField newField ) Void
protected CreateField ( ) DataControlField
protected FormatDataTextValue ( Object dataTextValue ) String
public Initialize ( Boolean sortingEnabled , Control control ) Boolean
public InitializeCell ( DataControlFieldCell cell , DataControlCellType cellType , DataControlRowState rowState , Int32 rowIndex ) Void
public ValidateSupportsCallback ( ) Void

Remarks

The ButtonField class is used by data-bound controls ( such as GridView and DetailsView ) to display a button for each record that is displayed. The ButtonField object is displayed differently depending on the data-bound control in which it is used. For example, the GridView control displays a ButtonField object as a column, while the DetailsView control displays it as a row.

Clicking a button in a button field raises the command event of the parent data-bound control. You can provide a custom routine to perform when a command button is clicked by providing an event handler for the command event.

NOTE: The GridView control raises the RowCommand event, while the DetailsView control raises the ItemCommand event.

To determine the index of the record that raises the command event, use the CommandArgument property of the event argument that is passed to the command event for the data-bound control. The ButtonField class automatically populates the CommandArgument property with the appropriate index value.

To specify the type of button to display, use the ButtonType property. When displaying a link or command button, use the Text property to specify the caption to display in the buttons.

NOTE: If you set the Text property, all buttons in a ButtonField share the same caption.

Alternatively, you can bind the ButtonField object to a field in a data source. This allows you to display different captions for the buttons in the ButtonField object. The values that are in the specified field are used for the text captions of the buttons. Set the DataTextField property to bind a ButtonField object to a field in a data source.

When displaying an image button, use the ImageUrl property to specify the image to display for the buttons in the ButtonField object.

NOTE: All buttons in a ButtonField object share the same image.

You can hide a ButtonField object in a data-bound control by setting the Visible property to false.

The ButtonField object allows you to customize its header and footer sections. To display a caption in the header or footer section, set the HeaderText or FooterText properties, respectively. Instead of displaying text in the header section, you can display an image by setting the HeaderImageUrl property. To hide the header section in a ButtonField object, set the ShowHeader property to false.

NOTE: Some data-bound controls ( such as the GridView control ) can show or hide only the entire header section of the control. These data-bound controls do not support the ShowHeader property for an individual button field. To show or hide the entire header section of a data-bound control ( if available ), use the ShowHeader property for the control.

You also can customize the appearance of the ButtonField object ( font color, background color, and so on ) by setting the style properties for the different parts of the field. The following table lists the different style properties.

Style property Description
ControlStyle The style settings for the child Web server controls of the ButtonField object.
FooterStyle The style settings for the footer section of the ButtonField object.
HeaderStyle The style settings for the header section of the ButtonField object.
ItemStyle The style settings for the data items in the ButtonField object.

See Also

BoundField   CheckBoxField   CommandField   HyperLinkField   ImageField   TemplateField Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph