有谁知道在一个asp.net的ListView隐藏列的方式吗? [英] Does anyone know of a way of hiding a column in an asp.net listview?

查看:184
本文介绍了有谁知道在一个asp.net的ListView隐藏列的方式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道你可以把<如果%在ItemTemplate%>语句来隐藏控件,但该列仍然存在。
你不能把<%%>语句插入这哪里是列标题宣告,因此问题LayoutTemplate模板。
有谁知道一个更好的办法?

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 which is where the column headings are declared, hence the problem. Does anyone know of a better way?

推荐答案

下面是另外一个解决方案,我只是做了,看到我明白你想要做什么:

Here's another solution that I just did, seeing that I understand what you want to do:

这是你的ASCX / ASPX

    <asp:ListView ID="ListView1" runat="server" DataSourceID="MyDataSource" ItemPlaceholderID="itemPlaceHolder" OnDataBound="ListView1_DataBound">
        <LayoutTemplate>
            <table border="1">
                <tr>
                    <td>Name</td>
                    <td>Age</td>
                    <td runat="server" id="tdIsSuperCool">IsSuperCool</td>
                </tr>
                <asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
            </table>
        </LayoutTemplate>
        <ItemTemplate>
            <tr>
                <td><%# Eval("Name") %></td>
                <td><%# Eval("Age") %></td>
                <td runat="server" id="myCol" visible='<%# (bool)Eval("IsSuperCool") %>'>true</td>
            </tr>
        </ItemTemplate>
    </asp:ListView>
    <asp:ObjectDataSource 
        ID="MyDataSource" 
        runat="server" 
        DataObjectTypeName="BusinessLogicLayer.Thing" 
        SelectMethod="SelectThings"
        TypeName="BusinessLogicLayer.MyObjectDataSource" />

这里的$ C $后面ç

/// <summary>
/// Handles the DataBound event of the ListView1 control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
protected void ListView1_DataBound(object sender, EventArgs e)
{
    ListView1.FindControl("tdIsSuperCool").Visible = false;
}

做你的数据绑定想要的。因为现在的列是RUNAT服务器,并且正在处理控​​件的数据绑定,当你做ListView1.FindControl(tdIsSuperCool),你在布局模板使作品像一个冠军。

Do whatever you want in the databound. Because the column is now runat server, and you're handling the DataBound of the control, when you do ListView1.FindControl("tdIsSuperCool") you're in the Layout template so that works like a champ.

这是你想放置任何业务逻辑控制TD的知名度,你是好。

Put whatever business logic that you want to control the visibility of the td and you're good.

这篇关于有谁知道在一个asp.net的ListView隐藏列的方式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆