Solved

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

Posted on 2010-08-24
4
1,123 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
  • 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
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…

776 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