Solved

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

Posted on 2010-08-24
4
1,149 Views
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?

Thx!
0
Comment
Question by:Eric3141
[X]
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
4 Comments
 
LVL 4

Assisted Solution

by:udaydidigam
udaydidigam earned 150 total points
ID: 33510466
0
 
LVL 2

Author Comment

by:Eric3141
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"
            AutoGenerateDeleteButton="True">
            <Columns>...

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;
0
 
LVL 16

Accepted Solution

by:
burakiewicz earned 350 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;
                        }
0
 
LVL 2

Author Comment

by:Eric3141
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.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
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.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
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…
Suggested Courses

630 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