RadGrid for ASP.NET

Command reference (Event bubbling in Telerik RadGrid) Send comments on this topic.
Insert/Update/Delete records > CommandItem > Command reference (Event bubbling in Telerik RadGrid)

Glossary Item Box

The ASP.NET page framework provides a technique called event bubbling that allows a child control to propagate events up its containment hierarchy. Event bubbling enables events to be raised from a more convenient location in the controls hierarchy and allows event handlers to be attached to the original control as well as to the control that exposes the bubbled event.

When an event bubbles from a child control, RadGrid will fire ItemCommand event. A child control (such as a Button server control) raises a bubble event if you set any value in CommandName property.


Merely the MS LinkButton, MS Button and MS ImageButton controls have CommandName property and can trigger the event bubbling mechanism of the grid.



For example the command name is "DoInsert" , then RadGrid will fire ItemCommandEvent and the event argument of the handler function (generally the "e" variable ) will have the same command name , i.e. "DoInsert" as a value for the e.CommandName property. Moreover, the e.Item argument will be a reference to the Item which is the parent of the control raised the bubble event (i.e. the Item where the button resides).

Some command names are predefined in RadGrid and the control will respond to them automatically (like the value of RadGrid.InitInsertCommandName constant or RadGrid.RefreshGridCommandName). The integrated paging in RadGrid is also based on commands, with CommandName "Page" (or RadGrid.PageCommandName) and command various arguments for different paging operations like the string "Next","Prev" or "First".

Here is a list of the available command names in Telerik RadGrid:

Fired By controls within DataItems - showing and editing data

CancelCommandName  Represents the Cancel command name. Fires RadGrid.CancelCommand event and sets Item.Edit to false for the parent Item.
DeleteCommandName Represents the Delete command name. Fires RadGrid.DeleteCommand event. Under .Net 2.0 this command can perform automatic delete operation.
UpdateCommandName  Represents the Update command name. Fires RadGrid.UpdateCommand event. Under .Net 2.0 this command can perform automatic update operation and then set Item.Edit to false.

EditCommandName 

Represents the Edit command name. Sets Item.Edit to true.

SelectCommandName 

Represents the Select command name. Sets Item.Selected to true

DeselectCommandName   

Represents the Deselect command name. Sets Item.Selected to false. 

Fired by controls within Items that have child items (in hierarchy structures or group structures)

ExpandCollapseCommandName 

Toggles the expanded state of the child items. 

Can be fired by controls within any Item

InitInsertCommandName

By default grid renders [Add new record] image button in the CommandItem. Opens the insert item.

PerformInsertCommandName

Fires RadGrid.InsertCommand event. Under .Net 2.0 Perfoms this command can perform automatic insert operation and close the insert item.

RebindGridCommandName

By default grid renders [Refresh] image button in the CommandItem. Forces RadGrid.Rebind

SortCommandName

Represents the Sort command name.  By default it is fired by image buttons in the header item when Sorting is enabled. The argument for the SortCommand must be the DataField name for the DataField to be sorted.

ExportToExcelCommandName

Exports grid data in Microsoft Excel ® format. You will need  to configure exporting settings for the grid through the RadGrid.ExportSettings section.

ExportToWordCommandName

Exports grid data in Microsoft Word ® format. You will need  to configure exporting settings for the grid through the RadGrid.ExportSettings section.

ExportToPdfCommandName

Exports grid data in PDF format. You will need  to configure exporting settings for the grid through the RadGrid.ExportSettings section.

ExportToCsvCommandName

Exports grid data in CSV format (comma-separated values). You will need  to configure exporting settings for the grid through the RadGrid.ExportSettings section.

Fired by controls within PagerItem

PageCommandName 

Represents the Page command name.  See also: Paging

Fired when the PageSize property is set and changed.

ChangePageSizeCommandName 

Fires RadGrid.PageSizeChanged event.

Fired when choosing an option from the filter menu within column header

FilterCommandName 

Represents the Filter command name.  See also: Operating with filter expression

Batch commands

EditSelectedCommandName 

Switches the selected grid items in edit mode automatically

DeleteSelectedCommandName 

Fires RadGrid.DeleteCommand event for the selected rows. Under .Net 2.0 can perform automatic delete operation for the selected rows.

UpdateEditedCommandName 

Fires Fires RadGrid.UpdateCommand event for the edited rows. Under .Net 2.0 can perform automatic update operation for the edited rows and then sets Item.Edit to false

EditAllCommandName 

Command that triggers editing for all grid records (AllowMultiRowEdit should be set to true).

CancelAllCommandName 

Cancels the previously undertaken actions.


This examples can help you with this approach (look at the ASCX code):
http://www.telerik.com/demos/aspnet/Grid/Examples/DataEditing/UserControlEditForm/DefaultCS.aspx

The user control buttons [Update] and [Cancel] have CommandName property associated. Both commands are handled by RadGrid.

ASPX/ASCXCopy Code
<td align="right" colspan="2">
<
asp:button id="btnUpdate" text="Update" CssClass="button" style="color:green;" runat="server"
commandname="Update"></asp:button>
<
asp:button id="btnCancel" text="Cancel" CssClass="button" runat="server" causesvalidation="False"
commandname="Cancel"></asp:button>
</
td>
</
tr>

When "Update" command bubbles, RadGrid will fire first ItemCommand event, and if the event is not canceled (e.Canceled set to false) then RadGrid will fire UpdateCommand event and then it will refresh automatically.

The "Cancel" command will close the edited item and will automatically refresh the grid.