Display or not a button in DataGrid-ButtonColumn

Posted on 2013-06-04
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?
Question by:allelopath
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
  • 4
  • 2
LVL 40

Accepted Solution

Kyle Abrahams earned 500 total points
ID: 39218952

change it to a template field.

instead of enabled just set the visible property.

Author Comment

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

Expert Comment

by:Kyle Abrahams
ID: 39220128
Yep.  Will work exactly the same.
Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.


Author Comment

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 ?

Author Comment

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'.

Author Comment

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

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

724 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