Web用户控件填充通过XML项目 [英] Web User Control Populate Items via XML

查看:156
本文介绍了Web用户控件填充通过XML项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web用户控件的名称图表控件,我有一个下拉图表控件内部列表
我想填充图表控件这样的下拉列表:

I have a web user control name as Chart Control, and I have a drop down List inside Chart Control I want to populate DropDown List of Chart Control like this:

<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 code

in .cs code

 [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;

                }
            }
}

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

When I compile and run it works fine for me, but at design time it says

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

我想即使在设计时解决它。
任何机构可以建议我据此?
谢谢你。

I want to work it even at design time. Can any body suggest me accordingly ? Thanks.

推荐答案

好吧,谷歌福小时后,我的结论是它要么不可能看到在设计内部子标签,或者没有人费心去给如何很好地回答这样做。

Ok, after hours of google-fu, I have concluded that it's either not possible to see inner child tags in the designer, or no one has bothered to give a good answer of how to do so.

根据 wonkim00的回答,这是从这个报价的 MSDN网站

According to wonkim00's answer, which is a quote from this MSDN site:

注意:模板化的ASP.NET用户控件不能在Visual Studio设计支持但是,您可以编译和运行在Visual Studio这个例子。要做到这一点,当你创建ASP.NET页面来测试这个code,更换所有的设计器生成的code与code和标记在示例列表的页面。

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.

然而,正如你所知,这是模板的通知,但我想它与许多其它数据类型(列表,集合的ArrayList)后,这似乎是相同的。

However, as you can tell, this is a notice for templates, but after me trying it out with many other datatypes (Lists, Collections, ArrayLists), It appears to be the same.

有可能是我们都缺少得到它在设计器中查看的属性,但它似乎是相当隐蔽(请,任何人随时证明我错了)。

There might be an attribute that we all are missing to get it viewable in the designer, but it seems to be quite hidden (please, anyone, feel free to prove me wrong).

我只是觉得这个奇怪的是,code编译和作品,但你不能让设计师闭嘴缺少的属性。

I just find this strange that the code compiles and works, but you can't get designer to shut up about missing properties.

链接我用:

  • 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

也许那些会帮助,也许不是。很抱歉的坏消息,但它是我能找到的最好的。

Maybe those will help, maybe not. Sorry for the bad news, but it's the best I could find.

这篇关于Web用户控件填充通过XML项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆