このhttp://blogs.msdn.com/b/mikeormond/archive/2008/07/26/dynamically-loading-listview-templates.aspx記事を (.ascx ファイルからの) 動的読み込みテンプレートの例として使用します。
これは作成者のコードです:
protected void Page_Load(object sender, EventArgs e)
{
ListView1.LayoutCreated += new EventHandler(ListView1_LayoutCreated);
ListView1.LayoutTemplate = LoadTemplate("LayoutTemplate.ascx");
ListView1.ItemTemplate = LoadTemplate("ItemTemplate.ascx");
}
void ListView1_LayoutCreated(object sender, EventArgs e)
{
//remove the layout template
ListView1.Controls.RemoveAt(0);
//recreate it
Control newLayoutContainer = new Control();
ListView1.LayoutTemplate.InstantiateIn(newLayoutContainer);
var userControl = newLayoutContainer.Controls[0];
userControl.ID = "MyLayout";
ListView1.Controls.Add(newLayoutContainer);
}
エラーが発生します:
ListView 'ListView1' で ItemTemplate を定義する必要があります。
ポストバック後。
どうしたの?ポストバック ( http://forums.asp.net/p/1305569/2558209.aspx )するたびに ListView を作成する必要がありますか?