控制這是我的文件後面的代碼:動態添加子控件的代碼在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>
我已經試過組模板和佔位符的控制。但我想我可能在佔位符方面犯了一個錯誤。 請爲我繪製這個錯誤! 在此先感謝。