Solved

Display or not a button in DataGrid-ButtonColumn

Posted on 2013-06-04
6
330 Views
Last Modified: 2013-06-11
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?
0
Comment
Question by:allelopath
  • 4
  • 2
6 Comments
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 39218952
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
 
LVL 1

Author Comment

by:allelopath
ID: 39219572
I have a DataGrid, not GridView. Will this work the same?
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 39220128
Yep.  Will work exactly the same.
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 1

Author Comment

by:allelopath
ID: 39230284
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
 
LVL 1

Author Comment

by:allelopath
ID: 39234791
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
 
LVL 1

Author Comment

by:allelopath
ID: 39239030
It does not work exactly the same. With a DataGrid, one must use <asp:TemplateColumn>
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question