Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.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# CompositeControl中的数据绑定控件_C#_Data Binding_Eval_Web Controls_Composite Controls - Fatal编程技术网

C# CompositeControl中的数据绑定控件

C# CompositeControl中的数据绑定控件,c#,data-binding,eval,web-controls,composite-controls,C#,Data Binding,Eval,Web Controls,Composite Controls,我创建了一个CompositeControl,它本质上是多视图的包装器,但是如果我尝试在视图中使用任何数据绑定控件,如GridView或FormView,我会得到错误: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control. 我已经把这门课精简到了最低限度,但我仍然得到了错误。该类如下所示: [DefaultProperty("

我创建了一个CompositeControl,它本质上是多视图的包装器,但是如果我尝试在视图中使用任何数据绑定控件,如GridView或FormView,我会得到错误:

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
我已经把这门课精简到了最低限度,但我仍然得到了错误。该类如下所示:

[DefaultProperty("Pages"), ParseChildren(true, "Pages"), ToolboxData("<{0}:TestTabs runat=\"server\"></{0}:TestTabs>")]
public class TestTabs : CompositeControl {

    private MultiView _multiViewControl;

    private Collection<View> _pages;
    public Collection<View> Pages {
        get {
            if (_pages == null) _pages = new Collection<View>();
            return _pages;
        }
    }

    protected override void CreateChildControls() {
        _multiViewControl = new MultiView();
        foreach (View page in Pages) { _multiViewControl.Views.Add(page); }
        if (_multiViewControl.Views.Count > 0) _multiViewControl.ActiveViewIndex = 0;

        this.Controls.Add(_multiViewControl);

        base.CreateChildControls();
    }
}
[DefaultProperty(“Pages”)、ParseChildren(true,“Pages”)、ToolboxData(“”)
公共类测试选项卡:CompositeControl{
专用多视图_多视图控件;
私人收藏网页;
公众收藏页{
得到{
如果(_pages==null)_pages=new Collection();
返回页面;
}
}
受保护的覆盖无效CreateChildControls(){
_multiViewControl=新的多视图();
foreach(查看页面中的页面){u multiViewControl.Views.Add(页面);}
如果(_multiViewControl.Views.Count>0)_multiViewControl.ActiveViewIndex=0;
this.Controls.Add(_multiViewControl);
base.CreateChildControls();
}
}
标记如下:

<cc:TestTabs ID="testTabs" runat="server">
    <asp:View runat="server">
        <asp:FormView ID="fvTest" runat="server">
            <ItemTemplate>
                <asp:Label ID="lblTest" runat="server" Text='<%#Eval("TestField")%>' />
            </ItemTemplate>
        </asp:FormView>
    </asp:View>
</cc:TestTabs>

如果我将FormView移到CompositeControl之外,它将毫无问题地进行数据绑定。此外,如果我使用标准的多视图,它也可以正常工作

有什么想法吗?提前感谢(第一篇帖子,如果我错过了任何信息,请道歉)

编辑:为了让事情变得更奇怪,如果我将FormView提取到一个单独的ascx用户控件中,并将其放在视图中,它就会工作


你可以继承
compositedaboundcontrol
而不是
CompositeControl

啊,很有趣,没想到。不幸的是,我已经找到了一种更好的使用Ajax TabContainer的方法,但如果我有时间,我将对此进行测试。谢谢