Show / Hide detail table 's column dynamically

6 posts, 1 answers
  1. Amol
    Amol avatar
    57 posts
    Member since:
    Apr 2008

    Posted 19 Feb 2009 Link to this post

    Hi All,

    I am using hierarchical grid which shows categories and its details.
    Now i want to show / hide columns which are in detail table depending on category.

    as follows, C1, C2 are categories and A, B, C are columns...

    -C1
        A  B  C
    -C2
        A C

    Please help me to solve my problem.

    Thanks,
    Amol Wable


  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 19 Feb 2009 Link to this post

    Hello Amol,

    You can try out the following code to hide columns in the DetailTable based on the cell values in its parent row:
    cs:
    protected void RadGrid1_PreRender(object sender, EventArgs e) 
        { 
            foreach (GridDataItem dataItem in RadGrid1.MasterTableView.Items) 
            { 
                if (dataItem.Expanded) 
                { 
                    GridTableView nestedTable = (GridTableView)dataItem.ChildItem.NestedTableViews[0]; 
                    if (dataItem["Category"].Text == "C2") 
                    { 
                        nestedTable.GetColumnSafe("ColumnBUniqueName").Visible = false
                    } 
                     
                } 
            }  
        } 

    Thanks
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Amol
    Amol avatar
    57 posts
    Member since:
    Apr 2008

    Posted 20 Feb 2009 Link to this post

    Excellent Princy,
    It works fine.

    Thanks,
    Amol Wable
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 20 Feb 2009 Link to this post

    Hi Amol,

    You can also refer the following help article which explains how to loop through detail tables in a hierarchical Grid.
    Traversing detail tables/items in Telerik RadGrid

    Thanks
    Shinu

  6. Mihir
    Mihir avatar
    3 posts
    Member since:
    Jul 2012

    Posted 27 Jul 2012 Link to this post

    Hi Princy,

    In my case, columns are defined as the part of MasterTableView. I want to hide the columns based on my code. So where should I exactly write the code to set the visibility false.
    At the moment I have defined it in ItemDataBound event but as it will fired this events for all items in my Grid, can i move it somewhere else where this visibility doesn't need to execute for all items...

    Thanks,
    Mihir
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 30 Jul 2012 Link to this post

    Hi,

    Try hiding the column in prerender event as shown below.
    C#:
    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
      RadGrid1.MasterTableView.GetColumn("UniqueName").Display = false;
    }

    Thanks,
    Shinu.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017