控制这是我的文件后面的代码:动态添加子控件的代码在ASP.NET C#中的ListView隐藏文件
ImageButton img = new ImageButton();
img.AlternateText = "<%# Eval(\"colA\") %>";
img.ImageUrl = "~/img.png";
img.ID = "img";
ListView3.Controls.Add(img);
ListView3.DataSource = ds; //DataSet containing column - colA with 20 rows
ListView3.DataBind();
我基本上是试图添加控制,这将一些处理后产生,到listview控件;但它不断给我的错误在
ListView3.DataBind();
An exception of type 'System.InvalidOperationException' occurred in System.Web.Extensions.dll but was not handled in user code Additional information: An item placeholder must be specified on ListView 'ListView3'. Specify an item placeholder by setting a control's ID property to "itemPlaceholder". The item placeholder control must also specify runat="server".
这是我ListView3代码:
<asp:ListView ID="ListView3" runat="server">
<LayoutTemplate>
<table id="itemPlaceholderContainer" runat="server">
<tr id="itemPlaceholder" runat="server"></tr>
</table>
</LayoutTemplate>
<ItemTemplate>
</ItemTemplate>
</asp:ListView>
我已经试过组模板和占位符的控制。但我想我可能在占位符方面犯了一个错误。 请为我绘制这个错误! 在此先感谢。