RadGrid NestedViewTemplate AutoExpand

2 posts, 0 answers
  1. Ken Jones
    Ken Jones avatar
    41 posts
    Member since:
    Sep 2009

    Posted 12 Apr 2011 Link to this post


    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?


  2. Jerry T.
    Jerry T. avatar
    118 posts
    Member since:
    Jul 2012

    Posted 12 Apr 2011 Link to this post

    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
            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.

Back to Top