asp.net – Web用户控件通过XML填充项目
我有一个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的引用:
但是,正如您所知,这是模板的通知,但在我尝试使用许多其他数据类型(列表,集合,数组列表)后,它似乎是相同的. 可能有一个我们都缺少的属性让它在设计器中可见,但它似乎非常隐藏(请,任何人,请随意证明我的错误). 我发现代码编译和工作很奇怪,但你不能让设计师关闭缺少的属性. 我用过的链接: > ASP NET Custom Control with PersistenceMode.InnerProperty including Server Controls 也许那些会有所帮助,也许不会.对不起的消息感到抱歉,但这是我能找到的最好的消息. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net – 如何将流excel文件转换为数据表C#?
- asp.net-mvc – 我们应该使用Entity Framework Code First方
- asp.net – 最佳实践:DataBound with loop vs RowDataBoun
- asp.net – 如何在主页面中包含CSS?
- asp.net – 无法加载文件或程序集’Microsoft.Office.Inter
- asp.net-mvc – 在MVC 4中获取表头名称的最佳方法
- asp.net-mvc – 如何在ASP.NET MVC控制器工厂中处理异常
- asp.net-mvc-3 – ExpandoObject,匿名类型和Razor
- 3.翻译系列:EF Code-First 示例(EF 6 Code-First系列)
- asp.net-mvc – 为什么Chrome在ASP.NET MVC中提供文件时搜索