Enabling/Disabling a DataGrid ButtonColumn

C

CGuy

Hi,

I have a datagrid that has one ButtonColumn which is bound to a database
field.

My requirement is that when the page containing the datagrid is loaded,
I would like the ButtonColumn to be enabled/disabled based on the value of a
boolean variable that is calculated at runtime - if the value if false, I
don't want the ButtonColumn to display links for the displayed items.

Please help me in doing this.

CGuy
 
C

CGuy

Nope... that would make the whole column vanish!!!

My requirement is that based on a variable's value, the column should behave
like a ButtonColumn or a Bound Colummn.

I was able to find a solution myself. This is how I'm doing it.

private void DataGrid_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
if(!ControlStatus)
{
//If ControlStatus is False, remove the LinkButton and Add a
Label
e.Item.Cells[1].Controls.RemoveAt(0);
Label labelItem = new Label();
labelItem.Text = "Text";
e.Item.Cells[1].Controls.Add(labelItem);
}
}
}


Rajesh.V said:
How about this?

MyDatagrid.Columns[0].Visible = false;

Hi,

I have a datagrid that has one ButtonColumn which is bound to a database
field.

My requirement is that when the page containing the datagrid is loaded,
I would like the ButtonColumn to be enabled/disabled based on the value
of
a
boolean variable that is calculated at runtime - if the value if false, I
don't want the ButtonColumn to display links for the displayed items.

Please help me in doing this.

CGuy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top