1

我希望以编程方式加载组模板和布局模板,但我收到以下错误消息:

定义 GroupTemplate 时,必须在 ListView 'Listview1' 上指定组占位符。通过将其 ID 属性设置为“ListView_GC$groupPlaceHolder1”来指定组占位符。组占位符控件还必须指定 runat="server"。

    protected void Listview1_Init(object sender, EventArgs e)
    {
        System.Diagnostics.Debug.WriteLine("in init");
        Listview1.ItemPlaceholderID = "ListView_UC$itemPlaceHolder1";
        Listview1.GroupPlaceholderID = "ListView_GC$groupPlaceHolder1";
        Listview1.GroupItemCount = 3;
        Listview1.LayoutTemplate = LoadTemplate("~/Controls/ThumbnailView_LayoutTemplate.ascx");
        Listview1.GroupTemplate = LoadTemplate("~/Controls/ThumbnailView_GroupTemplate.ascx");
        Listview1.ItemTemplate = LoadTemplate("~/Controls/ThumbnailView_ItemTemplate.ascx");

    }


    void Listview1_LayoutCreated(object sender, EventArgs e)
    {
       Listview1.Controls.RemoveAt(0);


        Control newLayoutContainer = new Control();

        Listview1.LayoutTemplate.InstantiateIn(newLayoutContainer);
        Listview1.GroupTemplate.InstantiateIn(newLayoutContainer); 
        var userControl = newLayoutContainer.Controls[0];
        var usergControl = newLayoutContainer.Controls[1];

        userControl.ID = "ListView_UC";
        usergControl.ID = "ListView_GC";

        Listview1.Controls.Add(newLayoutContainer);

    }

任何人都可以帮忙吗?

编辑:

控件的标记...

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ThumbnailView_GroupTemplate.ascx.cs" Inherits="myproject.Controls.ThumbnailView_GroupTemplate" %>
<tr>
    <asp:PlaceHolder ID="itemPlaceHolder1" runat="server" />
</tr>

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ThumbnailView_LayoutTemplate.ascx.cs" Inherits="myproject.Controls.ThumbnailView_LayoutTemplate" %>
<table>
    <asp:PlaceHolder ID="groupPlaceHolder1" runat="server" />
</table>
4

0 回答 0