Link to home
Start Free TrialLog in
Avatar of allelopath
allelopath

asked on

Display or not a button in DataGrid-ButtonColumn

I have a DataGrid with a column as a ButtonColumn. I need to display or not the button on a row-by-row basis based on data in the data binding. How do I do this?
ASKER CERTIFIED SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of allelopath
allelopath

ASKER

I have a DataGrid, not GridView. Will this work the same?
Yep.  Will work exactly the same.
Working on it. I have the asp setup, but not sure what to do with the btnDelete_DataBinding() method. The DataGrid data source is bound to a System.Collections.Generic.List<MyObjects>, so somehow this gets used in the method:
protected void btnDelete_DataBinding(object sender, System.EventArgs e)
{
    Button btn = (Button)(sender);
    btn.Entable = true;
    if (myObjectList (current element?).ACertainField.toString().Equals("someState")) {
        btn.Entable = false;
    }
}

Open in new window

the if statement above being the critical part. Can you suggest what to do ?
Also I get this run-time error:
Parser Error Message: System.Web.UI.WebControls.DataGridColumnCollection must have items of type 'System.Web.UI.WebControls.DataGridColumn'. 'asp:TemplateField' is of type 'System.Web.UI.WebControls.TemplateField'.
It does not work exactly the same. With a DataGrid, one must use <asp:TemplateColumn>