Asp.net 隐藏ListView表头以防代码隐藏

Asp.net 隐藏ListView表头以防代码隐藏,asp.net,vb.net,listview,Asp.net,Vb.net,Listview,我想隐藏一列基于角色的ListView,不让代码隐藏。以下是标记和代码: <asp:ListView ID="lvTimeSheet" runat="server"> <LayoutTemplate> <table id="TimeSheet"> <thead> <tr> <th id="thDelete

我想隐藏一列基于角色的ListView,不让代码隐藏。以下是标记和代码:

    <asp:ListView ID="lvTimeSheet" runat="server">
    <LayoutTemplate>
        <table id="TimeSheet">
            <thead>
                <tr>
                    <th id="thDelete" runat="server" Visible='<%# IsAdmin() %>'>
                         Select
                    </th>
                </tr>
            </thead>
            <tbody>
                <tr id="itemPlaceholder" runat="server" />
            </tbody>
        </table>
    </LayoutTemplate>
    <ItemTemplate>
        <tr>
            <td>
                <asp:CheckBox ID="cbMarkAsComplete" runat="server" onclick="selectMe(this)" Text=" &nbsp; Delete" />
            </td>
    </ItemTemplate>
</asp:ListView>

但该列id=“thDelete”始终可见。如何根据某些条件对代码隐藏列?感谢您的输入。

属性为runat=“server”的标记不允许包含在内。试试这个:

    <asp:ListView ID="lvTimeSheet" runat="server">
    <LayoutTemplate>
        <table id="TimeSheet">
            <thead>
<% If IsAdmin() Then %>

                <tr>
                    <th id="thDelete" runat="server">
                         Select
                    </th>
                </tr>
<% End If %>

            </thead>
            <tbody>
                <tr id="itemPlaceholder" runat="server" />
            </tbody>
        </table>
    </LayoutTemplate>
    <ItemTemplate>
        <tr>
            <td>
                <asp:CheckBox ID="cbMarkAsComplete" runat="server" onclick="selectMe(this)" Text=" &nbsp; Delete" />
            </td>
    </ItemTemplate>
</asp:ListView>

挑选
请尝试以下操作:

<LayoutTemplate>
    <table id="TimeSheet">
        <thead>
            <tr>
                <th id="thDelete" runat="server" Visible='<%# If( IsAdmin().tostring()="True", "true", "false") %>'>
                     Select
                </th>
            </tr>
        </thead>
        <tbody>
            <tr id="itemPlaceholder" runat="server" />
        </tbody>
    </table>
</LayoutTemplate>`

挑选
`

您确定IsAdmin函数返回的值为false吗?是的,即使我将函数更改为仅返回false,它仍然可见。
<LayoutTemplate>
    <table id="TimeSheet">
        <thead>
            <tr>
                <th id="thDelete" runat="server" Visible='<%# If( IsAdmin().tostring()="True", "true", "false") %>'>
                     Select
                </th>
            </tr>
        </thead>
        <tbody>
            <tr id="itemPlaceholder" runat="server" />
        </tbody>
    </table>
</LayoutTemplate>`