Enabling/Disabling a DataGrid ButtonColumn

  • Thread starter Thread starter CGuy
  • Start date Start date
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
 
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
 
Back
Top