我正在使用 VS2010,我有一个带有 ListView 的 aspx 页面。现在我想隐藏具有 ID 的 ListView 列。
我已经厌倦了这段代码:
ListView1.Columns[0].Width = 0;
但它不会让我,它在'columns'部分给出一个错误,说“ system.web.ui.webcontrols.listview不包含'columns'的定义并且没有扩展方法'columns'接受第一个参数找不到类型“system.web.ui.webcontrols.listview”(您是否缺少 using 指令或程序集引用?) “。
我也试过这段代码:
ListView1.FindControl("idTh").Visible = false;
foreach (ListViewItem item in ListView1.Items)
{
item.FindControl("idCol").Visible = false;
}
但它给了我一个“未设置为引用的对象”错误。
我究竟做错了什么??
这是我的 aspx 代码:
<asp:ListView ID="ListView1" runat="server" DataSourceID="Paysment_Dates"
InsertItemPosition="LastItem"
onselectedindexchanged="ListView1_SelectedIndexChanged">
<AlternatingItemTemplate>
<tr class="t_even">
<td>
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td >
<asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
</td>
<td>
<asp:Label ID="PublishYearLabel" runat="server"
Text='<%# Eval("PublishYear") %>' />
</td>
<td>
<asp:Label ID="PublishMonthLabel" runat="server"
Text='<%# Eval("PublishMonth") %>' />
</td>
<td>
<asp:Label ID="PayDteLabel" runat="server" Text='<%# Eval("PayDte") %>' />
</td>
<td>
<asp:Label ID="PublishDteLabel" runat="server"
Text='<%# Eval("PublishDte") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<EditItemTemplate>
<tr style="">
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update"
Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Cancel" />
</td>
<td>
<asp:TextBox ID="IDTextBox" runat="server" Text='<%# Bind("ID") %>' />
</td>
<td>
<asp:TextBox ID="PublishYearTextBox" runat="server"
Text='<%# Bind("PublishYear") %>' />
</td>
<td>
<asp:TextBox ID="PublishMonthTextBox" runat="server"
Text='<%# Bind("PublishMonth") %>' />
</td>
<td>
<asp:TextBox ID="PayDteTextBox" runat="server" Text='<%# Bind("PayDte") %>' />
</td>
<td>
<asp:TextBox ID="PublishDteTextBox" runat="server"
Text='<%# Bind("PublishDte") %>' />
</td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
<table runat="server" style="">
<tr>
<td>
No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert"
Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Clear" />
</td>
<td>
<asp:TextBox ID="IDTextBox" runat="server" Text='<%# Bind("ID") %>' />
</td>
<td>
<asp:TextBox ID="PublishYearTextBox" runat="server"
Text='<%# Bind("PublishYear") %>' />
</td>
<td>
<asp:TextBox ID="PublishMonthTextBox" runat="server"
Text='<%# Bind("PublishMonth") %>' />
</td>
<td>
<asp:TextBox ID="PayDteTextBox" runat="server" Text='<%# Bind("PayDte") %>' />
</td>
<td>
<asp:TextBox ID="PublishDteTextBox" runat="server"
Text='<%# Bind("PublishDte") %>' />
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr class="t_odd">
<td>
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td id="idCol" runat="server">
<asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
</td>
<td>
<asp:Label ID="PublishYearLabel" runat="server"
Text='<%# Eval("PublishYear") %>' />
</td>
<td>
<asp:Label ID="PublishMonthLabel" runat="server"
Text='<%# Eval("PublishMonth") %>' />
</td>
<td>
<asp:Label ID="PayDteLabel" runat="server" Text='<%# Eval("PayDte") %>' />
</td>
<td>
<asp:Label ID="PublishDteLabel" runat="server"
Text='<%# Eval("PublishDte") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table ID="itemPlaceholderContainer" runat="server" border="0" style="">
<tr runat="server" style="">
<th runat="server">
</th>
<th id="idTh" runat="server">
ID</th>
<th runat="server">
Publish Year</th>
<th runat="server">
Publish Month</th>
<th runat="server">
Pay Date</th>
<th runat="server">
Publish Date</th>
</tr>
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style="">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True"
ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<tr style="">
<td>
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
</td>
<td>
<asp:Label ID="PublishYearLabel" runat="server"
Text='<%# Eval("PublishYear") %>' />
</td>
<td>
<asp:Label ID="PublishMonthLabel" runat="server"
Text='<%# Eval("PublishMonth") %>' />
</td>
<td>
<asp:Label ID="PayDteLabel" runat="server" Text='<%# Eval("PayDte") %>' />
</td>
<td>
<asp:Label ID="PublishDteLabel" runat="server"
Text='<%# Eval("PublishDte") %>' />
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>