ListView disable Insert and Edit buttons based on role
I've a requirement to disable edit/create buttons in ListView.Could anyone please show me how to enable or disable Edit/Create buttons in ListView from code behind, please.
Not sure if this is possible.
<InsertItemTemplate>
<tr>
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert"
Text="Insert" CssClass="button"
ValidationGroup="InsertValidation" CausesValidation="true" />
<asp:Button ID="CancelButton" runat="server" Com开发者_开发百科mandName="Cancel"
Text="Clear" CssClass="button" />
</td>
</tr>
</InsertItemTemplate>
Use RolePrincipal.IsInRole.
The code should be similiar to the following:
void listView_ItemDataBound(...)
{
Button targetButton = (Button) e.Item.FindControl("TargetButtonName");
targetButton.Enabled = User.IsInRole("Administrators");
}
Refer to how to enable and disable button based on user role?
精彩评论