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

GridTemplateColumn visibility

3 Answers 884 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brad
Top achievements
Rank 1
Brad asked on 04 May 2011, 01:36 PM
Hi all, I am having trouble with the visible property of an  GridTemplateColumn.

I have an AutoGenerated EditType edit screen because of the dynamic nature of the requirement. I have added a necessary dropdown onto this edit area by adding an GridTemplateColumn to the <Columns> area of the radgrid.

I need this GridTemplateColumn to only be visible under certain circumstances but I have no luck. Setting the visible property = "false" in the tag itself does not work. Nor does setting the .Display, .ReadOnly or .Visible properties in the code behind. I have tried hooking into the column in both ItemDataBound and PreRender events. I have tried finding the column from the MasterTable and other methods as well.

Every time I find the column correctly (verified by debugging the UniqueName) but the column is always visible.

I tried adding a label inside the GridTemplateColumn and set EditFormHeaderTextFormat to an empty string but the column space is reserved and thus my label is indented.

A solution to either would solve this issue. Need some help please!

Thanks :)

EDIT - My column is of type EditItemTemplate so that it shows on the Edit Form. If I change it to ItemTemplate I am able to make the column Visible = false

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 04 May 2011, 01:52 PM
Hello Brad,

You can achieve this by attaching PreRender event to your RadGrid. Try the following code snippet. Hope this helps you.

C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
 {
    RadGrid1.MasterTableView.GetColumn("ColumnUniqueName").Visible = false;          
}

Thanks,
Shinu
0
Brad
Top achievements
Rank 1
answered on 04 May 2011, 01:57 PM
Thanks Shinu,

This works fine for columns of type ItemType but not EditItemType.

And if I set my column to ItemType I can't find the control within in the code behind.

Thoughts?

And thanks for the quick reply.

EDIT - I can't hide any of the other Edit columns either. It would be important to note that EditType="AutoGenerated" again
0
Brad
Top achievements
Rank 1
answered on 04 May 2011, 02:46 PM
Well since you guys seem to be one-n-done with replies as a general practice, here is what I did to resolve the issue:

You have to set the ReadOnly property, not the Visible property. I set mine to false in the tag.

And then in the PreRender you have to check it as so:


if

 

(condition)

 

 

{

 

 

foreach (GridColumn col in gv.MasterTableView.RenderColumns)

 

 

{

 

 

if (col.UniqueName.ToLower() == "gtc")

 

 

{

 

 

GridTemplateColumn gtc = (GridTemplateColumn)col;

 

 

gtc.ReadOnly =

false;

 

 

}

}

}

 

else

 

{

 

foreach (GridColumn col in gv.MasterTableView.RenderColumns)

 

 

{

 

 

if (col.UniqueName.ToLower() == "gtc")

 

 

{

 

 

GridTemplateColumn gtc = (GridTemplateColumn)col;

 

 

gtc.ReadOnly =

true;

 

 

}

 

}

 

}


Tags
Grid
Asked by
Brad
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Brad
Top achievements
Rank 1
Share this question
or