Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用InAdminContainer创建自定义控件?_C#_Asp.net_Controltemplate_Naming Containers - Fatal编程技术网

C# 如何使用InAdminContainer创建自定义控件?

C# 如何使用InAdminContainer创建自定义控件?,c#,asp.net,controltemplate,naming-containers,C#,Asp.net,Controltemplate,Naming Containers,我正在尝试以下方法: [PersistenceMode(PersistenceMode.InnerProperty)] [TemplateContainer(typeof(TemplateContainer))] public virtual ITemplate LayoutTemplate { get; set; } protected void Page_Init(object sender, EventArgs e) { this.Controls.Clear(); i

我正在尝试以下方法:

[PersistenceMode(PersistenceMode.InnerProperty)]
[TemplateContainer(typeof(TemplateContainer))]
public virtual ITemplate LayoutTemplate { get; set; }

protected void Page_Init(object sender, EventArgs e)
{
    this.Controls.Clear();

    if (LayoutTemplate != null)
    {
        var data = Enumerable.Range(0, 10);

        foreach (int index in data)
        {
            TemplateContainer container = new TemplateContainer(index);

            LayoutTemplate.InstantiateIn(container);

            this.Controls.Add(container);
        }
    }
}
我的容器类别:

public class TemplateContainer : Control, INamingContainer
{
    public int Index { get; set; }

    internal TemplateContainer(int index)
    {
        this.Index = index;
    }
}
和我的标记:

<uc:TemplateControl ID="ucTemplateControl" runat="server">
    <LayoutTemplate>
        <b>Index:</b>
        <asp:TextBox ID="Literal1" runat="server"
            Text='<%# Container.Index %>'
            ReadOnly="true" />
        <br />
    </LayoutTemplate>
</uc:TemplateControl>

索引:


要绑定值,需要调用自定义控件的
DataBind
方法

召唤

ucTemplateControl.DataBind();

从该页开始,将数据绑定到模板上。

要绑定值,需要调用自定义控件的
DataBind
方法

召唤

ucTemplateControl.DataBind();
从该页开始,将数据绑定到模板上。

完全控制文件:完全控制文件: