如何从ASP.NET的listview中删除列标头
本文关键字:删除列 listview ASP NET | 更新日期: 2023-09-27 18:12:23
是否可以在ASP中删除列标头?. NET列表视图控件?
<asp:ListView ID="ListView1" class="lv" runat="server" DataSourceID="SqlDataSource1"
onprerender="ListView1_PreRender"
onselectedindexchanged="ListView1_SelectedIndexChanged"
style="text-align: left">
使用LayoutTemplate,您可以定义列,然后使用OnLayoutCreated事件隐藏特定列。
<asp:ListView ID="ListView1" class="lv" runat="server" DataSourceID="SqlDataSource1"
onprerender="ListView1_PreRender"
onselectedindexchanged="ListView1_SelectedIndexChanged"
style="text-align: left" OnLayoutCreated="OnLayoutCreated">
<LayoutTemplate>
<table id="itemPlaceholderContainer">
<tr>
<td><asp:Label id="columnToHide" runat="server" Text="Column 1" /></td>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td><%#Eval("name")></td>
</tr>
</ItemTemplate>
然后在代码后面:
protected void OnLayoutCreated(object sender, EventArgs e)
{
this.ListView1.FindControl("columnToHide").Visible = false;
}
尝试使用ItemTemplate,不要在LayoutTemplate中定义标题行。
链接到ListView web服务器控件概述:http://msdn.microsoft.com/en-us/library/bb398790 (v = vs.100) . aspx
链接到ListView web服务器控件类定义和示例:http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.aspx
试试这个
<asp:Listview id="listview1" runat="server" DataSourceID="sqldatasource1">
<LayoutTemplate>
<table id="itemPlaceholderContainer">
<tr runat="server" id="itemPlaceholder">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<asp:HyperLink runat="server" text='<%#Eval("name")>'></asp:HyperLink>
</td>
</tr>
</ItemTemplate>
</asp:Listview>