Does anyone know of a way of hiding a column in an asp.net listview?

前端 未结 7 1757
悲哀的现实
悲哀的现实 2021-01-17 14:45

I know you can put <% if %> statements in the ItemTemplate to hide controls but the column is still there. You cannot put <% %> statements into the LayoutTemplate whic

相关标签:
7条回答
  • 2021-01-17 15:41

    The ListView gives you full control about how the data is rendered to the client. You specify the Layout Template, and give a placeholder which will be where each item is injected.

    The output of the below will give you a table, and each item will be a new TR.

    Notice the use of runat='server' and visible ='<%# %>'

    <asp:ListView ID="ListView1" runat="server" DataSourceID="MyDataSource" ItemPlaceholderID="itemPlaceHolder">
        <LayoutTemplate>
            <table>
                <asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
            </table>
        </LayoutTemplate>
        <ItemTemplate>
            <tr>
                <td runat="server" id="myCol" visible='<%# (bool)Eval("IsSuperCool") %>'>
                    <%# Eval("SuperCoolIcon") %>
                </td>
                <td>
                    <%# Eval("Name") %>
                </td>
                <td>
                    <%# Eval("Age") %>
                </td>
            </tr>
        </ItemTemplate>
    </asp:ListView>
    
    0 讨论(0)
提交回复
热议问题