(1) traverse all items in the grid (one row), expand only one row at a time [single expand in hierarchical grid]
Private void radgrid1_itemcommand (Object source, telerik. Web. UI. gridcommandeventargs E)
{
If (E. commandname = radgrid. expandcollapsecommandname)
{
Foreach (griditem item in E. Item. ownertableview. Items)
{
If (item. Expanded & item! = E. item)
{
Item. Expanded = false;
}
}
}
}
Http://www.telerik.com/help/aspnet-ajax/grdsingleexpandinhierarchicalgrid.html
(2) Expand or collapse all rows
Protected void radgrid1_itemcommand (Object source, telerik. webcontrols. gridcommandeventargs E)
{
If (E. commandname = radgrid. expandcollapsecommandname)
{
(E. Item. findcontrol ("btnexpand") as imagebutton). Visible =! (E. Item. findcontrol ("btnexpand") as imagebutton). visible;
(E. Item. findcontrol ("btncollapse") as imagebutton). Visible =! (E. Item. findcontrol ("btncollapse") as imagebutton). visible;
}
If (E. commandname = "expandall ")
{
// Looping through each dataitem and making the "btnexpand" image button in the item visibility to false and "btncollapse" visibility to true
Foreach (griddataitem in radgrid1.mastertableview. getitems (New griditemtype [] {griditemtype. Item, griditemtype. alternatingitem }))
{
Imagebutton btnexpand = (imagebutton) griddataitem. findcontrol ("btnexpand ");
Btnexpand. Visible = false;
Imagebutton btncollapse = (imagebutton) griddataitem. findcontrol ("btncollapse ");
Btncollapse. Visible = true;
}
// Exapanding the dataitem
Foreach (griddataitem item in radgrid1.items)
{
Item. Expanded = true;
}
// Hiding the collapseall image in the header to true and expandall image in the header to false
Gridheaderitem = E. item as gridheaderitem;
Imagebutton imgcollapseall = (imagebutton) gridheaderitem. findcontrol ("collapseall ");
Imgcollapseall. Visible = true;
Imagebutton imgexpandall = (imagebutton) gridheaderitem. findcontrol ("expandall ");
Imgexpandall. Visible = false;
}
If (E. commandname = "collapseall ")
{
// Looping through each dataitem and making the "btnexpand" image button in the item visibility to true and "btncollapse" visibility to false
Foreach (griddataitem in radgrid1.mastertableview. getitems (New griditemtype [] {griditemtype. Item, griditemtype. alternatingitem }))
{
Imagebutton btnexpand = (imagebutton) griddataitem. findcontrol ("btnexpand ");
Btnexpand. Visible = true;
Imagebutton btncollapse = (imagebutton) griddataitem. findcontrol ("btncollapse ");
Btncollapse. Visible = false;
}
// Collapsing the dataitem
Foreach (griddataitem item in radgrid1.items)
{
Item. Expanded = false;
}
// Hiding the collapseall image in the header to false and expandall image in the header to true
Gridheaderitem = E. item as gridheaderitem;
Imagebutton imgcollapseall = (imagebutton) gridheaderitem. findcontrol ("collapseall ");
Imgcollapseall. Visible = false;
Imagebutton imgexpandall = (imagebutton) gridheaderitem. findcontrol ("expandall ");
Imgexpandall. Visible = true;
}
}
Http://www.telerik.com/community/code-library/aspnet-ajax/grid/custom-expand-collapse-column-with-expandall-collapseall-image-button-in-the-header.aspx
(3) cause the grid to rebind data [commands that invoke rebind () implicitly]
Here is the complete list of commands that triggerRebind():
Command Name
Field
Expandcollapse
Radgrid. expandcollapsecommandname
Update
Radgrid. updatecommandname
Cancel
Radgrid. cancelcommandname
Delete
Radgrid. deletecommandname
Edit
Radgrid. editcommandname
Initinsert
Radgrid. initinsertcommandname
Performinsert
Radgrid. incluminsertcommandname
Rebindgrid
Radgrid. rebindgridcommandname
Page
Radgrid. pagecommandname
Sort
Radgrid. sortcommandname
Filter
Radgrid. filtercommandname
Note that the following commandsDo notPerform internal rebind:
Select
Radgrid. selectcommandname
Deselect
Radgrid. deselectcommandname
Http://www.telerik.com/help/aspnet-ajax/grdcommandsthatinvokerebindimplicitly.html