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

Visibility of buttons in GridTemplateColumn

2 Answers 84 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eric Skaggs
Top achievements
Rank 2
Eric Skaggs asked on 05 Dec 2008, 03:31 PM
if (e.Item is GridDataItem)  
            {  
                GridDataItem dataItem = (GridDataItem)e.Item;  
                  
                if (dataItem["Scenario"].Text == "Scenario1")  
                {  
                    foreach (Control ctrl in dataItem["Action"].Controls)  
                    {  
                        ctrl.Visible = false;  
                    }  
                    dataItem["Action"].Controls[1].Visible = true;    
                }  
                else if (dataItem["Scenario"].Text == "Scenario2")  
                {  
                    //Do something else  
                } 

Hello,

I have a GridTemplateColumn in my grid in which there are three LinkButton controls.  Based on values in the current item, I need to be able to either show or hide these LinkButtons.  The code above is from my grid's ItemDataBound event.  As you can see, I'm accessing the controls in the column by their index.  Isn't there a better way?  Who knows what other controls might be in there that I'm unaware of...I might NOT want all of them to be invisible.

Eric Skaggs

2 Answers, 1 is accepted

Sort by
0
Accepted
Lenny_shp
Top achievements
Rank 2
answered on 05 Dec 2008, 03:39 PM
Try dataItem["Action"].FindControl("yourcontrolname").Visible = true;
0
Eric Skaggs
Top achievements
Rank 2
answered on 05 Dec 2008, 04:00 PM
I honestly thought I had tried that, but I did it just now and it worked perfectly.  Thanks for the help.  :)

Eric Skaggs
Tags
Grid
Asked by
Eric Skaggs
Top achievements
Rank 2
Answers by
Lenny_shp
Top achievements
Rank 2
Eric Skaggs
Top achievements
Rank 2
Share this question
or