我有一个 Web 用户控件名称作为图表控件,我在图表控件中有一个下拉列表我想像这样填充图表控件的下拉列表:
<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'"
即使在设计时我也想工作。任何机构都可以相应地建议我吗?谢谢。