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

Show / Hide detail table 's column based on column Value of Parent Table

2 Answers 196 Views
Grid
This is a migrated thread and some comments may be shown as answers.
gc_0620
Top achievements
Rank 1
gc_0620 asked on 27 May 2011, 03:32 AM
Folks using VS 2010 SP1 with Rad Controls for ASP.Net Ajax 2011. I am below link as prototype. But unlike the below link I have 1 Master and 1 detail table.

http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/declarativerelations/defaultcs.aspx

My intention is for example if CustomerID column value is 'ALFKI' in parent Table then hide Freight (A GridTemplateColumn in my actual scenario) Data in Detail Table, else show Frieght Column data in Detail Table. So far I come up with this in Radgrid Prerender event but strugling to get a referrence to hide the Detail Table column.

protected void RadGrid1_PreRender(object sender, EventArgs e)  
    {  
        foreach (GridDataItem dataItem in RadGrid1.MasterTableView.Items)  
        {  
            if (dataItem.Expanded)  
            {  
                // Need Help here to Conditionally Hide Detail Table Freight Column
                     //  if Column Value CustomerID  of Parent Table =  'ALFKI'.
                    
            }  
        }   
    }

Thanks

gc_0620

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 27 May 2011, 05:04 AM
Hello GC,

Try the following code snippet in ItemDataBound event to hide the required column.

C#:
protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)
{
   if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "DetalTable1")
  {
           GridTableView detailTable = (GridTableView)e.Item.OwnerTableView;
           detailTable.GetColumn("Freight").Display = false;
  }
 }


Thanks,
Princy.
0
gc_0620
Top achievements
Rank 1
answered on 27 May 2011, 08:12 PM
Thanks Princy, as always, your help is appreciated.

Regards,

GC_0620
Tags
Grid
Asked by
gc_0620
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
gc_0620
Top achievements
Rank 1
Share this question
or