Enable or disable the delete link in the GridView according to the role of the logged in user

In some scenarios you may only want users of a particular role to delete records from the GridView. So you need a mechanism to disable/hide the delete link in the gridview based on roles. The code below will enable the delete link only for “Admin” roles and disable it for the rest.


Protected Sub gridView1_RowDataBound(ByVal sender As Object, ByVal e As system.Web.UI.WebControls.GridViewRowEventArgs) Handles Gridview1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If User.IsInRole("Admin") Then
Dim DeleteLink As LinkButton = CType(e.Row.FindControl("HyperLinkDelete"), LinkButton)
DeleteLink.Enabled = true
else
DeleteLink.Enabled = True
End If
End If
End Sub

Related posts:

  1. Efficient Search Engine Friendly Gridview Paging control The Gridview Control in ASP.NET has built in paging support....
  2. Format dates in a Gridview column To format a gridview column to display dates properly ,...

Related posts brought to you by Yet Another Related Posts Plugin.

One Response to “Enable or disable the delete link in the GridView according to the role of the logged in user”

  1. Thank u so much….it hepled..:)

Leave a Reply