RadControls for ASP.NET AJAX
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.
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
Represents the Cancel command name. Fires RadGrid.CancelCommand event and sets Item.Edit to false for the parent Item.
Represents the Delete command name. Fires RadGrid.DeleteCommand event. Under .Net 2.0 this command can perform automatic delete operation.
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.
Represents the Edit command name. Sets Item.Edit to true.
Represents the Select command name. Sets Item.Selected to true.
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)
Toggles the expanded state of the child items.
Can be fired by controls within any Item
By default grid renders [Add new record] image button in the CommandItem. Opens the insert item.
Fires RadGrid.InsertCommand event. Under .Net 2.0 Perfoms this command can perform automatic insert operation and close the insert item.
By default grid renders [Refresh] image button in the CommandItem. Forces RadGrid.Rebind
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.
Exports grid data in Microsoft Excel ® format. You will need to configure exporting settings for the grid through the RadGrid.ExportSettings section.
Exports grid data in Microsoft Word ® format. You will need to configure exporting settings for the grid through the RadGrid.ExportSettings section.
Exports grid data in PDF format. You will need to configure exporting settings for the grid through the RadGrid.ExportSettings section.
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
Represents the Page command name. See also: Paging
Fired when the PageSize property is set and changed.
Fires RadGrid.PageSizeChanged event.
Fired when choosing an option from the filter menu within column header
Represents the Filter command name. See also: Operating with filter expression
Switches the selected grid items in edit mode automatically
Fires RadGrid.DeleteCommand event for the selected rows. Under .Net 2.0 can perform automatic delete operation for the selected rows.
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
Command that triggers editing for all grid records (AllowMultiRowEdit should be set to true).
Cancels the previously undertaken actions.
Command triggered when you click a row and have ClientSettings -> EnablePostBackOnRowClick set to true (see this demo)
Command triggered when a Download button in a GridAttachmentColumn is clicked for a GridDataItem (see this demo)
This examples can help you with this approach (look at the ASCX code):
The user control buttons
CommandName property associated. Both commands are handled by RadGrid.
<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">
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.Furthermore, here are the internally recognized command arguments you can check:
Paging command arguments
Indicates that the end user chose to navigate to the first page in the grid
Indicates that the end user chose to navigate to the next page in the grid
Indicates that the end user chose to navigate to the previous page in the grid
Indicates that the end user chose to navigate to the last page in the grid
Note that you can also set the CommandArgument property of a built-in GridButtonColumn or a LinkButton/Button/ImageButton residing in GridTemplateColumn to a custom value and then intercept the ItemCommand event to determine the command argument for the clicked button (if needed).