Expand/Collapse one or several rows

5 posts, 0 answers
  1. Jürgen
    Jürgen avatar
    2 posts
    Member since:
    Dec 2012

    Posted 05 Apr 2013 Link to this post

    Hello,

    how to expand/collapse one or several rows/colums in codebehind?

    Thanks in advance!
  2. Kostadin
    Admin
    Kostadin avatar
    1711 posts

    Posted 10 Apr 2013 Link to this post

    Hello Jürgen,

    I am not completely sure whether you want to expand/collapse hierarchy grid or a grid groups. If you want to expand/collapse hierarchy items you could hook OnPreRender event handler and loop through all items and set their Expanded property to true/false. Check out the following code snippet.
    protected void gridView_PreRender(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
                {
                    item.Expanded = true;
                }
            }
        }

    If you want to expand/collapse grid groups you could use the same approach but instead looping through the RadGrid items you should loop through the GridGroupHeaderItem collection.
    protected void RadGrid1_PreRender(object sender, EventArgs e)
        {
            if (Page.IsPostBack)
            {
                foreach (GridGroupHeaderItem item in RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader))
                {
                    if (int.Parse(item.GroupIndex) % 2 == 0)
                    {
                        item.Expanded = false;
                    }
                }
            }
        }


    Greetings,
    Kostadin
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jürgen
    Jürgen avatar
    2 posts
    Member since:
    Dec 2012

    Posted 16 Apr 2013 Link to this post

    Hello Kostadin,

    Thanks, it's working as expected.
  5. Roman
    Roman avatar
    1 posts
    Member since:
    Jul 2013

    Posted 15 Jul 2013 Link to this post

    Hi,

    This is not working for RadPivotGrid because RadPivotGrid do not have MasterTableView definition. Pasted code works for RadGrid, but not for RadPivotGrid. Is this possible for RadPivotGrid?
  6. Kostadin
    Admin
    Kostadin avatar
    1711 posts

    Posted 18 Jul 2013 Link to this post

    Hello Roman,

    Please review the following live example where only one of the column groups is expanded.

    Regards,
    Kostadin
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017