...我想在用户是管理员时显示“删除”按钮,并在用户是贡献者时显示“添加项目”按钮:
<!-- More code above -->
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton CSSClass="TableRightLink" ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
Visible=<%# User.IsInRole(@"DOMAIN\CMDB_ADMIN") %>
Text="Delete"
OnClientClick="return confirm('Are you certain you want to delete this item?');"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<SelectedRowStyle VerticalAlign="Top" />
<HeaderStyle ForeColor="White" CssClass="TableHeader" BackColor="SteelBlue" />
</asp:GridView>
<asp:table width="100%" runat="server" CSSclass="PromptTable" Visible=<%# User.IsInRole(@"DOMAIN\CMDB_CONTRIBUTE") %> >
<asp:tablerow><asp:tablecell HorizontalAlign=Center>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="AddConfigItem.aspx" ForeColor="LightCyan">Add Item</asp:HyperLink>
</asp:tablecell></asp:tablerow></asp:table>
删除按钮“可见”属性工作正常。但是,“添加项目”超链接没有。它总是显示。查看源告诉我 %# User.IsInRole(@"DOMAIN\CMDB_CONTRIBUTE") %> 没有评估任何东西。知道这是为什么吗?