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>
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.
According to wonkim00's answer, which is a quote from this MSDN site:
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).
I just find this strange that the code compiles and works, but you can't get designer to shut up about missing properties.
Links I used:
Maybe those will help, maybe not. Sorry for the bad news, but it's the best I could find.
Make sure your class is called
ChartControl
and that its derived fromUserControl
not fromControl
this could be the reason for this error, hope this helps.