...我想要显示的“删除”按钮,当用户是管理员,并显示“添加项”按钮,当用户是一个贡献者:为什么User.IsInRole不能在这种情况下工作?
<!-- 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”)%>不计算任何东西。 ?
错误无法为'Visible'属性的字符串表示形式'<%= User.IsInRole(@“DOMAIN \ CMDB_CONTRIBUTE”)%>'创建类型为'System.Boolean'的对象。 – Kolten 2008-10-28 22:53:36