Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Can't hide GridView Delete button programmatically -- help!

Posted on 2010-08-24
Medium Priority
Last Modified: 2012-05-10
We're using C#.
Need to hide Delete button on GridView programmatically when user has certain roles, etc.
Found this online and looks great but does not hide Delete button:

this.GridView1.AutoGenerateDeleteButton = false;

I"ve tried putting it in the Page_Load event handler and the GridView1_RowDataBound event handler.

I'd like to use this command as it seems very straigtforward.  Ideas?

Question by:Eric3141
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
  • 2

Assisted Solution

udaydidigam earned 600 total points
ID: 33510466

Author Comment

ID: 33510857
I tried this but it can't get it to work.  Ideas on what I'm doing wrong?

I looked at the article and now have this in my source view of aspx page:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="True"
            DataKeyNames="intCaseActionHistoryID" DataSourceID="odsCaseActionHistory"

The article did not say to do this but I changed AutoGenerateColumns="False" to "True".

Then in my page_load I have:

GridView1.AutoGenerateDeleteButton= false;
LVL 16

Accepted Solution

burakiewicz earned 1400 total points
ID: 33515015
you could do something like this in the rowdatabound if that is not working
if (((LinkButton)e.Row.Cells[0].Controls[2]).Text.Equals("Delete", StringComparison.CurrentCultureIgnoreCase))
                            e.Row.Cells[0].Controls[2].Visible = false;

Author Comment

ID: 33527019
Uday:  I tried that and it works.  I prefer to do that sort of thing in the .cs page, though - just my preference.

Bura - I made the delete button a template field then did Find Control then set Visible = false;
Works great.

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

705 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