Export (0) Print
Expand All

FormView.ItemCommand Event

Note: This event is new in the .NET Framework version 2.0.

Occurs when a button within a FormView control is clicked.

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

public:
event FormViewCommandEventHandler^ ItemCommand {
	void add (FormViewCommandEventHandler^ value);
	void remove (FormViewCommandEventHandler^ value);
}
/** @event */
public void add_ItemCommand (FormViewCommandEventHandler value)

/** @event */
public void remove_ItemCommand (FormViewCommandEventHandler value)

JScript supports the use of events, but not the declaration of new ones.

The ItemCommand event is raised when a button within the FormView control is clicked. This allows you to provide an event-handling method that performs a custom routine whenever this event occurs.

Buttons within a FormView control can also invoke some of the built-in functionality of the control. To perform one of these operations, set the CommandName property of a button to one of the values in the following table.

CommandName value

Description

"Cancel"

Cancels an edit or insert operation and returns the FormView control to the mode specified by the DefaultMode property. Raises the ModeChanged and ModeChanging events.

"Delete"

Deletes the current record. Raises the ItemDeleted and ItemDeleting events.

"Edit"

Puts the FormView control in edit mode. Raises the ModeChanged and ModeChanging events.

"Insert"

Inserts the current record in the data source. Raises the ItemInserted and ItemInserting events.

"New"

Puts the FormView control in insert mode. Raises the ModeChanged and ModeChanging events.

"Page"

Performs a paging operation. Set the CommandArgument property of the button to "First", "Last", "Next", "Prev", or a page number to specify the type of paging operation to perform. Raises the PageIndexChanged and PageIndexChanging events.

"Update"

Updates the current record in the data source. Raises the ItemUpdated and ItemUpdating events.

Although the ItemCommand event is raised when a button listed in the previous table is clicked, it is recommended that you use the events listed in the table for the operation.

A FormViewCommandEventArgs object is passed to the event-handling method, which allows you to determine the command name and command argument of the button clicked. To determine the command name and command argument, use the CommandName and CommandArgument properties, respectively. You can also access the control that raised the event by using the CommandSource property.

For more information about handling events, see Consuming Events.

The following example demonstrates how to use the ItemCommand event to handle a button click in a FormView control. When the user clicks the Add button, the currently displayed item is added to a ListBox control.

No code example is currently available or this language may not be supported.

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

Community Additions

ADD
Show:
© 2014 Microsoft