加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – ListView禁用基于角色的插入和编辑按钮

发布时间:2020-12-16 10:00:28 所属栏目:asp.Net 来源:网络整理
导读:我要求在ListView中禁用编辑/创建按钮.有人请告诉我如何在代码后面启用或禁用ListView中的编辑/创建按钮. 不确定这是否可行. InsertItemTemplate tr td asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" CssClass="button"
我要求在ListView中禁用编辑/创建按钮.有人请告诉我如何在代码后面启用或禁用ListView中的编辑/创建按钮.

不确定这是否可行.

<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" CommandName="Cancel" 
                Text="Clear" CssClass="button" />
        </td>
    </tr>
</InsertItemTemplate>

解决方法

使用 RolePrincipal.IsInRole.

代码应类似于以下内容:

void listView_ItemDataBound(...)
{
    Button targetButton = (Button) e.Item.FindControl("TargetButtonName");

    targetButton.Enabled = User.IsInRole("Administrators");
}

参见how to enable and disable button based on user role?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读