Link to home
Start Free TrialLog in
Avatar of Eric3141
Eric3141Flag for Afghanistan

asked on

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

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!
SOLUTION
Avatar of udaydidigam
udaydidigam

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Eric3141

ASKER

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;
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.