W
Warped
I am trying to make a simple user control that contains a Label and a
DropDownList. Basically, I want this control to expose some of the
Label's properties (e.g. Text) and some of the DropDownList's
properties (e.g. Items) and have the designer handle them
appropriately. Exposing Label.Text wasn't a problem, but I can't get
DropDownList.Items to work. I added an Items property to my codebhind
class like this.
public partial class LabelledDropDown : System.Web.UI.UserControl
{
public ListItemCollection Items
{
get { return this.DropDownList1.Items; }
}
}
When I place an instance of the user control on a web form, the Items
property does appear in the designer, but the designer doesn't treat it
as an editable collection. How do I make that happen?
Also, any items I add to the collection via the designer should be
"remembered" in the .aspx file as nested elements, like this.
<uc1:LabelledDropDown ID="LabelledDropDown1" runat="server"
LabelText="Screen size">
<asp:ListItem>Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
</uc1:LabelledDropDown>
This functionality would be relatively simple in .NET WinForms, so I
assume it can be done in WebForms as well.
DropDownList. Basically, I want this control to expose some of the
Label's properties (e.g. Text) and some of the DropDownList's
properties (e.g. Items) and have the designer handle them
appropriately. Exposing Label.Text wasn't a problem, but I can't get
DropDownList.Items to work. I added an Items property to my codebhind
class like this.
public partial class LabelledDropDown : System.Web.UI.UserControl
{
public ListItemCollection Items
{
get { return this.DropDownList1.Items; }
}
}
When I place an instance of the user control on a web form, the Items
property does appear in the designer, but the designer doesn't treat it
as an editable collection. How do I make that happen?
Also, any items I add to the collection via the designer should be
"remembered" in the .aspx file as nested elements, like this.
<uc1:LabelledDropDown ID="LabelledDropDown1" runat="server"
LabelText="Screen size">
<asp:ListItem>Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
</uc1:LabelledDropDown>
This functionality would be relatively simple in .NET WinForms, so I
assume it can be done in WebForms as well.