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

I need to hide expand image based on condition.

3 Answers 153 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joby
Top achievements
Rank 1
Joby asked on 28 Mar 2012, 10:01 AM
Hi,
I need to make hierarchical grid based on some condition.This means if there is no details,then there should not be (+) image in the grid.I need to hide expand image based on condition.Each master row i have the status of whether detail is there or not.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 28 Mar 2012, 10:08 AM
Hello Joby,

Try the following code in PreRender event to hide ExpandCollapseColumn when there are no child records.
C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    HideExpandColumnRecursive(RadGrid1.MasterTableView);
}
public void HideExpandColumnRecursive(GridTableView tableView)
{
    GridItem[] nestedViewItems = tableView.GetItems(GridItemType.NestedView);
    foreach (GridNestedViewItem nestedViewItem in nestedViewItems)
    {
      foreach (GridTableView nestedView in nestedViewItem.NestedTableViews)
      {
        if (nestedView.Items.Count == 0)
        {
          TableCell cell = nestedView.ParentItem["ExpandColumn"];
          cell.Controls[0].Visible = false;
          cell.Text = " ";
          nestedViewItem.Visible = false;
        }
       if (nestedView.HasDetailTables)
       {
        HideExpandColumnRecursive(nestedView);
        }
      }
   }
}

Thanks,
Princy.
0
Joby
Top achievements
Rank 1
answered on 28 Mar 2012, 10:32 AM
Hi Princy,
Thank for the reply.when i am using this code,this will remove all (+)images.But i don't want this.I need to remove (+) based on some condition.
0
Princy
Top achievements
Rank 2
answered on 29 Mar 2012, 01:33 PM
Hi Joby,

I guess you are using HierarchyLoadMode="ServerOnDemand".If so the DataBind of a child GridTableView would only take place when an item is Expanded. So initially the count of child will be null and it will hide Expandcollapse image for all Grid rows.

Thanks,
Princy
Tags
Grid
Asked by
Joby
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Joby
Top achievements
Rank 1
Share this question
or