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

How to hide/display a GridTemplateColumn ?

2 Answers 1161 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stephane
Top achievements
Rank 1
Stephane asked on 02 Mar 2011, 11:08 AM
Hello,

I have a RadGrid control with a GridTemplateColumn. I need to hide an "Action" TemplateColumn in Edit mode and to display that colum in normal mode. I defined the following ItemDatabound event to hide the "Action" TemplateColumn:

protected void oRgRoulement_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
           // Hide the Action TemplateColumn in edit mode
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)
                   (oRgRoulement.MasterTableView.GetColumn("Action") as GridTemplateColumn).Visible = false;
        }

What should I do to display the action TemplateColumn when the user will leave the edit mode ? In other words, how to determine if a row is already in edit mode ?

Thanks,

Steven




2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 02 Mar 2011, 11:36 AM
Hello,


A better approach is setting the visibility in PreRender event as shown below.

Code:
protected void RadGrid1_PreRender1(object sender, EventArgs e)
{
    if (RadGrid1.EditIndexes.Count > 0)
    {
        RadGrid1.MasterTableView.GetColumn("templateColumnUniqueName").Visible = false;
    }
    else
    {
        RadGrid1.MasterTableView.GetColumn("templateColumnUniqueName").Visible = true;
    }
}




Thanks,
Princy.
0
Jess
Top achievements
Rank 1
answered on 19 Jun 2012, 08:34 PM
If I just have the need to hide/show a GridTemplateColumn based on the user's authentication in an Active Directory group can I do that in ItemDataBound or do I need to do it in PreRender? The reason I ask is that I need to execute the code to determine if the user is in the AD group to allow them to see the column. 

thanks!
Tags
Grid
Asked by
Stephane
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jess
Top achievements
Rank 1
Share this question
or