DetailsViewCommandEventArgs Class
Provides data for the ItemCommand event.
Assembly: System.Web (in System.Web.dll)
The DetailsView control raises the ItemCommand event when a button within a ButtonField, CommandField, or TemplateField row field is clicked. This allows you to provide an event handler that performs a custom routine whenever this event occurs.
Note: |
|---|
The DetailsView control also raises other specialized events when certain buttons are clicked (buttons with the CommandName property set to "Delete", "Insert", "Page", or "Update"). When using one of these buttons, you should consider using one of the specialized events provided by the control (such as ItemDeleted or ItemDeleting). |
A DetailsViewCommandEventArgs object is passed to the event handler. If the button that raised the event has a command name or command argument value, you can use the DetailsViewCommandEventArgs object to determine these values. To determine the command name and command argument of the button clicked, use the CommandName and CommandArgument properties, respectively. You can also access the DetailsView control that raised the event by using the CommandSource property.
For a list of initial property values for an instance of the DetailsViewCommandEventArgs class, see the DetailsViewCommandEventArgs constructor.
The following code example demonstrates how to use the DetailsViewCommandEventArgs object passed to the event handler for the ItemCommand event to determine the command name of the button clicked by the user. This example uses the single-file coding model.
The following code example shows a code-behind coding model version of the previous example. For this example to work, you must copy the code below into the associated code-behind file.
The following code example shows the code-behind file for the previous example.
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page { public void ItemDetailsView_ItemCommand(Object sender, DetailsViewCommandEventArgs e) { // Use the CommandName property to determine which button // was clicked. if (e.CommandName == "Add") { // Add the customer to the customer list. // Get the row that contains the company name. In this // example, the company name is in the second row (index 1) // of the DetailsView control. DetailsViewRow row = ItemDetailsView.Rows[1]; // Get the company's name from the appropriate cell. // In this example, the company name is in the second cell // (index 1) of the row. String name = row.Cells[1].Text; // Create a ListItem object with the company name. ListItem item = new ListItem(name); // Add the ListItem object to the ListBox control, if the // item does not already exist. if (!CustomerListBox.Items.Contains(item)) { CustomerListBox.Items.Add(item); } } } }
- AspNetHostingPermission
for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
- AspNetHostingPermission
for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.
System::EventArgs
System.Web.UI.WebControls::CommandEventArgs
System.Web.UI.WebControls::DetailsViewCommandEventArgs
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.
Note: