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>
<asp:LinkButton ID=”LinkButton2″ runat=”server” CausesValidation=”False” Visible=’<%# GetShowInsertButton() %>’
CommandName=”New” Text=”New”></asp:LinkButton>
<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
Thank you! It works on my project.
Comment by Judy — November 4, 2009 @ 3:27 pm
can you convert the code to vb.net? thank you
Comment by john — November 9, 2009 @ 4:50 am
Thank you Judy hope this helps you
Good Luck
Comment by yasserzaid — November 9, 2009 @ 11:33 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.
Comment by yasserzaid — November 9, 2009 @ 11:34 am