Click here to Skip to main content
15,905,322 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello!!!
I have 2 roles admin and user. They both have access to same page (default.aspx) This page has a gridview with update and delete button. what i want to do is disable the delete and edit button or hide them if user is in role "USER".

Please tell me how to do this.
Posted

1 solution

While viewing the page, you must be having the information if the current user is an admin or user. Based on this information, you will set the visibility of the control.

Use grid's RowDataBound method to set the visiblity.
VB
Protected Sub GridView_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
        Dim rtype As DataControlRowType = e.Row.RowType
        If ((rtype = DataControlRowType.DataRow)  _
                    AndAlso ((rtype <> DataControlRowType.Footer)  _
                    AndAlso ((rtype <> DataControlRowType.Separator)  _
                    AndAlso ((rtype <> DataControlRowType.Header)  _
                    AndAlso (rtype <> DataControlRowType.Pager))))) Then
            ' Get the delete button 
            ' Use Role
            ' Disable if not Admin
            If (currentRole <> "Admin") Then
                Dim btn As Button = CType(e.Row.FindControl("DeleteButton1"),Button)
                btn.Enabled = false
            End If
        End If
    End Sub

Try!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900