Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Display or not a button in DataGrid-ButtonColumn

Posted on 2013-06-04
6
329 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

792 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