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

Column visibility in Hierarchy grid

6 Answers 142 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bottlerocket
Top achievements
Rank 1
Bottlerocket asked on 07 May 2009, 07:25 AM
Hi,
     I have to make a column invisible in a childgrid based on some conditions. Some thing like i have 3 columns and i have to show/hide these columns depending on some conditions. I tried to do it under DetailTableDataBind method, but in vain. My code is something like this:
DetailTableDataBind Method
begin
                If<Condition is true>
                 Hide these columns i.e.    e.DetailTableView.GetColumnSafe("ColumnName").visible=false;
               else
                Hide these columns
end.
By default all these columns are visible and AutogenerateColumns is set to false. I also took a variable and assigned a value in DetailTableDataBind event and used it under columnCreating, columnCreated events just to make sure that it does n't work. Can somebody help me in this issue.

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 07 May 2009, 08:09 AM
Hi,

Can you try hiding the Grid column using the display property and see whether it is working.

CS:
 
   if (e.Item.OwnerTableView.Name == "Detail"
        { 
            e.Item.OwnerTableView.GetColumn("ColumnName").Display= false
         
        } 


Thanks
Shinu
0
Bottlerocket
Top achievements
Rank 1
answered on 07 May 2009, 11:44 AM
Hi,
     Thanks very much for the response. But, like i said, i have to do this in DetailTableDataBind event and your snippet does n't workout. The scenario is like Detailtable's columns differ based on some conditions. OK, I did it in some other manner and   presented the data in the child table finally. I took a toggle column(Its a normal databoundcolumn) in child table  and assigned different values and dataformats depending on the conditions in code behind page. Now, my problem is  I have to change the column header of this toggle column as well depending on the conditions. I tried with default properties and it does n't work. Can you help me with that. I'm pasting a copy of snippet .

DetailTableDataBind()
{
........
........
                                InstColumn1 = (GridBoundColumn)e.DetailTableView.GetColumnSafe("ToggleColumn");
                                InstColumn1.DataField = "instanceId";
                                InstColumn1.DataFormatString = "Instance {0}";
.......
.......
}

R/ BottleRocket
0
Emad
Top achievements
Rank 1
answered on 03 Jan 2012, 05:18 PM
I have the same problem but readonly in hierarchy

I used the below code to make the item as readonly in edit mode and editable in insert mode , this work fine
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {
            GridNumericColumn groupcode = e.Item.OwnerTableView.GetColumnSafe("COMPANY_CODE") as GridNumericColumn;
            //GridNumericColumn
 
            if (e.CommandName == RadGrid.InitInsertCommandName)//insert mode
            {
                groupcode.ReadOnly = false; //user can insert group code
            }
            else if (e.CommandName == RadGrid.EditCommandName)//update mode
            {
                groupcode.ReadOnly = true;//user can not update group code
            }
        }

but i use same logic with hierarchy table it gives error
here's the code which gives error with first line
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {
            GridDropDownColumn systemcode = e.Item.OwnerTableView.DetailTables[0].GetColumnSafe("SYSTEM_CODE") as GridDropDownColumn;
            GridDropDownColumn modulecode = e.Item.OwnerTableView.DetailTables[0].GetColumnSafe("MODULE_CODE") as GridDropDownColumn;
            GridDropDownColumn pagecode = e.Item.OwnerTableView.DetailTables[0].GetColumnSafe("PAGE_CODE") as GridDropDownColumn;
            if (e.CommandName == RadGrid.InitInsertCommandName)//insert mode
            {
                systemcode.ReadOnly = false; //user can insert system code
                modulecode.ReadOnly = false;
                pagecode.ReadOnly = false;
            }
            else if (e.CommandName == RadGrid.EditCommandName)//update mode
            {
                systemcode.ReadOnly = true;//user can not update system code
                modulecode.ReadOnly = true;
                pagecode.ReadOnly = true;
            }
        }

Please advice
Emad
0
Shinu
Top achievements
Rank 2
answered on 04 Jan 2012, 06:15 AM
Hello Emad,

Try the following code.
C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
 if (e.Item is GridEditableItem && e.Item.IsInEditMode && !(e.Item is GridEditFormInsertItem) && e.Item.OwnerTableView.Name == "Master")
 {
   GridEditableItem editFormItem = (GridEditableItem)e.Item;
   RadComboBox ddl = (RadComboBox)editFormItem["ddl"].Controls[0];
   ddl.Enabled = false;
 }
}

-Shinu.
0
Emad
Top achievements
Rank 1
answered on 04 Jan 2012, 06:58 AM
Hello Shinu,

Thanks for your reply. I can't use your code because I use GridDropDownColumn not RadComboBox.
I solve it by the below code but still i have problem that this code not fire in first time

i.e
when you click edit first time the item appear in edit form then cancel then edit again these items not appear which is correct !!!!!!!
do you know why ???

 

protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {
            GridDropDownColumn systemcode = (GridDropDownColumn)RadGrid1.MasterTableView.DetailTables[1].GetColumnSafe("SYSTEM_CODE");
            GridDropDownColumn modulecode = (GridDropDownColumn)RadGrid1.MasterTableView.DetailTables[1].GetColumnSafe("MODULE_CODE");
            GridDropDownColumn pagecode   = (GridDropDownColumn)RadGrid1.MasterTableView.DetailTables[1].GetColumnSafe("PAGE_CODE");
  
            if (e.CommandName == RadGrid.InitInsertCommandName && e.Item.OwnerTableView.Name == "GroupSystems")//insert mode
            {
                systemcode.ReadOnly = false; //user can insert system code
                modulecode.ReadOnly = false;
                pagecode.ReadOnly   = false;
            }
            else if (e.CommandName == RadGrid.EditCommandName && e.Item.OwnerTableView.Name == "GroupSystems")//update mode
            {
                systemcode.ReadOnly = true; //user can not update system code
                modulecode.ReadOnly = true;
                pagecode.ReadOnly   = true;
            }
              
        }

 



Please advice
Emad
0
Emad
Top achievements
Rank 1
answered on 04 Jan 2012, 08:04 AM
Hi Shinu,

I'm sorry your code is working fine.

Thanks
Emad
Tags
Grid
Asked by
Bottlerocket
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Bottlerocket
Top achievements
Rank 1
Emad
Top achievements
Rank 1
Share this question
or