Home > ASP.Net > Disable Edit and Insert and New Buttons in DetailsView according to Roles

Disable Edit and Insert and New Buttons in DetailsView according to Roles


Hi

try this example :-

<asp:TemplateField ShowHeader="False">
    <ItemTemplate>
         <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" Visible='<%# GetShowEditButton() %>'
                             CommandName="Edit" Text="Edit"></asp:LinkButton>
         &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" Visible='<%# GetShowInsertButton() %>'
                             CommandName="New" Text="New"></asp:LinkButton>
         &nbsp;<asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="False"
                             CommandName="Delete" Text="Delete" Visible='<%# GetShowDeleteButton() %>'></asp:LinkButton>
    </ItemTemplate>
</asp:TemplateField>

in your codebehind, you have the following:

   

 protected bool GetShowEditButton()
    {
        return Roles.IsUserInRole("Admin");
    }
    protected bool GetShowInsertButton()
    {
        return Roles.IsUserInRole("Admin");
    }
    protected bool GetShowDeleteButton()
    {
        return Roles.IsUserInRole("Admin");
    }

Hope this helps

Good Luck

Advertisements
Categories: ASP.Net
  1. Judy
    November 4, 2009 at 3:27 pm

    Thank you! It works on my project.

  2. john
    November 9, 2009 at 4:50 am

    can you convert the code to vb.net? thank you

  3. yasserzaid
    November 9, 2009 at 11:33 am

    Thank you Judy hope this helps you
    Good Luck

  4. yasserzaid
    November 9, 2009 at 11:34 am

    Hi John
    try this using vb.net

    Protected Function GetShowEditButton() As Boolean
    Return Roles.IsUserInRole(Admin)
    End Function
    Protected Function GetShowInsertButton() As Boolean
    Return Roles.IsUserInRole(Admin)
    End Function
    Protected Function GetShowDeleteButton() As Boolean
    Return Roles.IsUserInRole(Admin)
    End Function

    Good Luck.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: