加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – Web用户控件通过XML填充项目

发布时间:2020-12-16 06:32:18 所属栏目:asp.Net 来源:网络整理
导读:我有一个Web用户控件名称作为Chart Control,我在Chart Control中有一个下拉列表 我想填充DropDown图表控件列表,如下所示: UC:ChartControl ID="abc" runat="server" ChartDropDownItems asp:ListItem Text="Graph_Amount_Items_Sold" Value="0"/asp:ListIte
我有一个Web用户控件名称作为Chart Control,我在Chart Control中有一个下拉列表
我想填充DropDown图表控件列表,如下所示:

<UC:ChartControl ID="abc" runat="server">
        <ChartDropDownItems>
            <asp:ListItem Text="Graph_Amount_Items_Sold" Value="0"></asp:ListItem>
            <asp:ListItem Text="Graph_Ranking" Value="1"></asp:ListItem>
            <asp:ListItem Text="Graph_Share_Amount_Items_Sold" Value="2"></asp:ListItem>
            <asp:ListItem Text="Graph_Share_Unit_items_Sold" Value="3" Selected="True"></asp:ListItem>
            <asp:ListItem Text="Graph_Unit_items_Sold" Value="4"></asp:ListItem>
        </ChartDropDownItems>
    </UC:ChartControl>

在.cs代码中

[DefaultProperty("ChartDropDownItems"),ParseChildren(true,"ChartDropDownItems"),PersistChildren(false),ToolboxData("<{0}:ChartControl runat="server"> </{0}:ChartControl>")]

    public partial class ChartControl : System.Web.UI.UserControl
    {
     private List<ListItem> lst;
            [Browsable(true)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            [PersistenceMode(PersistenceMode.InnerProperty)]

            public List<ListItem> ChartDropDownItems
            {
                set
                {
                    lst = value;
                    Bind_ddChartChange();
                }
            }
     private void Bind_ddChartChange()
            {

                if (lst != null)
                {
                    ddChartChange.DataSource = lst;
                    ddChartChange.DataTextField = "Text";
                    ddChartChange.DataValueField = "Value";
                    ddChartChange.DataBind();
                    ListItem li = lst.Find(x => x.Selected == true);
                    ddChartChange.SelectedValue = li.Value;

                }
            }
}

当我编译并运行它对我来说工作正常,但在设计时它说

"Error Creating Control"
"Type'System.Web.UI.Control' does not have a public property named 'ChartDropDownItems'"

我想在设计时工作.
任何身体可以相应地建议我吗?
谢谢.

解决方法

好吧,经过几个小时的google-fu之后,我得出的结论是,要么设计师不能看到内在的儿童标签,要么没有人愿意给出如何做到这一点的好答案.

根据wonkim00’s answer,这是MSDN site的引用:

Note: Templated ASP.NET user controls are not supported in the Visual Studio designer. However,you can compile and run this example in Visual Studio. To do so,when you create ASP.NET pages to test this code,replace all the designer-generated code in the pages with the code and markup in the example listings.

但是,正如您所知,这是模板的通知,但在我尝试使用许多其他数据类型(列表,集合,数组列表)后,它似乎是相同的.

可能有一个我们都缺少的属性让它在设计器中可见,但它似乎非常隐藏(请,任何人,请随意证明我的错误).

我发现代码编译和工作很奇怪,但你不能让设计师关闭缺少的属性.

我用过的链接:

> ASP NET Custom Control with PersistenceMode.InnerProperty including Server Controls
> Aleris’s Answer for Custom elements in ASP.NET with custom child-elements
> MSDN How to: Create Templated ASP.NET User Controls (see comments)
> How do I get design mode to work for templated user controls?
> How to Fix Visual Studio Error ‘System.Web.UI.UserControl’ does not contain a definition for

也许那些会有所帮助,也许不会.对不起的消息感到抱歉,但这是我能找到的最好的消息.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读