Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.WebControls.GridCommandEventArgs) |
If e.CommandName = RadGrid.ExpandCollapseCommandName Then |
(TryCast(e.Item.FindControl("btnExpand"), ImageButton)).Visible = Not (TryCast(e.Item.FindControl("btnExpand"), ImageButton)).Visible |
(TryCast(e.Item.FindControl("btnCollapse"), ImageButton)).Visible = Not (TryCast(e.Item.FindControl("btnCollapse"), ImageButton)).Visible |
End If |
If e.CommandName = "ExpandAll" Then |
'Looping through each DataItem and making the "btnExpand" image button in the item visibility to false and "btnCollapse" visibility to true |
For Each GridDataItem As GridDataItem In RadGrid1.MasterTableView.GetItems(New GridItemType() {GridItemType.Item, GridItemType.AlternatingItem}) |
Dim btnExpand As ImageButton = DirectCast(GridDataItem.FindControl("btnExpand"), ImageButton) |
btnExpand.Visible = False |
Dim btnCollapse As ImageButton = DirectCast(GridDataItem.FindControl("btnCollapse"), ImageButton) |
btnCollapse.Visible = True |
Next |
'Exapanding the DataItem |
For Each item As GridDataItem In RadGrid1.Items |
item.Expanded = True |
Next |
'Hiding the CollapseAll image in the header to true and ExpandAll image in the header to false |
Dim GridHeaderItem As GridHeaderItem = TryCast(e.Item, GridHeaderItem) |
Dim imgCollapseAll As ImageButton = DirectCast(GridHeaderItem.FindControl("CollapseAll"), ImageButton) |
imgCollapseAll.Visible = True |
Dim imgExpandAll As ImageButton = DirectCast(GridHeaderItem.FindControl("ExpandAll"), ImageButton) |
imgExpandAll.Visible = False |
End If |
If e.CommandName = "CollapseAll" Then |
'Looping through each DataItem and making the "btnExpand" image button in the item visibility to true and "btnCollapse" visibility to false |
For Each GridDataItem As GridDataItem In RadGrid1.MasterTableView.GetItems(New GridItemType() {GridItemType.Item, GridItemType.AlternatingItem}) |
Dim btnExpand As ImageButton = DirectCast(GridDataItem.FindControl("btnExpand"), ImageButton) |
btnExpand.Visible = True |
Dim btnCollapse As ImageButton = DirectCast(GridDataItem.FindControl("btnCollapse"), ImageButton) |
btnCollapse.Visible = False |
Next |
'Collapsing the DataItem |
For Each item As GridDataItem In RadGrid1.Items |
item.Expanded = False |
Next |
'Hiding the CollapseAll image in the header to false and ExpandAll image in the header to true |
Dim GridHeaderItem As GridHeaderItem = TryCast(e.Item, GridHeaderItem) |
Dim imgCollapseAll As ImageButton = DirectCast(GridHeaderItem.FindControl("CollapseAll"), ImageButton) |
imgCollapseAll.Visible = False |
Dim imgExpandAll As ImageButton = DirectCast(GridHeaderItem.FindControl("ExpandAll"), ImageButton) |
imgExpandAll.Visible = True |
End If |
End Sub |
Protected Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As EventArgs) |
'Hiding the default expand/collapse image |
For Each item As GridItem In RadGrid1.MasterTableView.Controls(0).Controls |
If TypeOf item Is GridNestedViewItem Then |
Dim nestedViewItem As GridNestedViewItem = TryCast(item, GridNestedViewItem) |
Dim cell As TableCell = nestedViewItem.NestedTableViews(0).ParentItem("ExpandColumn") |
Dim expandCollapseButton As ImageButton = TryCast(cell.Controls(0), ImageButton) |
expandCollapseButton.Visible = False |
End If |
Next |
|
End Sub |