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?
LVL 1
allelopathAsked:
Who is Participating?
 
Kyle AbrahamsSenior .Net DeveloperCommented:
http://stackoverflow.com/questions/6834634/enabling-and-disabling-buttons-in-gridview

change it to a template field.

instead of enabled just set the visible property.
0
 
allelopathAuthor Commented:
I have a DataGrid, not GridView. Will this work the same?
0
 
Kyle AbrahamsSenior .Net DeveloperCommented:
Yep.  Will work exactly the same.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
allelopathAuthor Commented:
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 ?
0
 
allelopathAuthor Commented:
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'.
0
 
allelopathAuthor Commented:
It does not work exactly the same. With a DataGrid, one must use <asp:TemplateColumn>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.