This is a migrated thread and some comments may be shown as answers.

RadGrid NestedViewTemplate AutoExpand

1 Answer 174 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ken Jones
Top achievements
Rank 1
Ken Jones asked on 12 Apr 2011, 01:39 PM
Hello,

I have a RadGrid with a NestedViewTemplate inside it. I wish to expand the first row of the NestedViewTemplate when the page first loads.

I have been unable to acheive this so far, can anyone suggest how best to acheive this?

Thanks,

Ken

1 Answer, 1 is accepted

Sort by
0
Jerry T.
Top achievements
Rank 1
answered on 12 Apr 2011, 04:08 PM
You might try something like this in the DataBound event:

Dim parentGrid As RadGrid = DirectCast(sender, RadGrid)
  
parentGrid.Items(0).Expanded = True


I do this to toggle expanding/collapsing the parent grid row when clicked:

Private Sub parentGrid_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles parentGrid.ItemCommand
    If (e.CommandName = "RowClick") Then
        Dim parentGrid As RadGrid = DirectCast(sender, RadGrid)
        Dim gdi As GridDataItem = parentGrid.MasterTableView.Items(e.Item.ItemIndex)
        Dim ni As GridNestedViewItem = gdi.ChildItem
        Dim nestedGrid As RadGrid = DirectCast(ni.FindControl("nestedGrid"), RadGrid)
        For Each gdi2 As GridDataItem In parentGrid.Items
            If (gdi2.ItemIndex <> gdi.ItemIndex) Then gdi2.Expanded = False
        Next
        gdi.Expanded = Not gdi.Expanded
    End If
End Sub

There's actually a bit more that I have in there (some JavaScript) as clicking on a row in the nested grid causes the parent grid ItemCommand to fire which causes all kinds of issues, at least for me in this app and Telerik is aware of this and is apparently working on not firing events at the parent level when they occur on a nested grid.  See my post from March 2 here: http://www.telerik.com/community/forums/aspnet-ajax/grid/itemcommands-for-nested-radgrid.aspx


Hope that helps.

Jerry
Tags
Grid
Asked by
Ken Jones
Top achievements
Rank 1
Answers by
Jerry T.
Top achievements
Rank 1
Share this question
or