Home All Groups Group Topic Archive Search About

DropDownList in composite control not saving ListItems

Author
26 May 2005 5:27 PM
Steve Trandahl
I have a composite control consisting of a DropdownList control and a button.
I've included an Items property that returns a reference to the
DropDownList's Items property, but when I add ListItems to it in Design mode,
they aren't added as <asp:ListItem> in the HTML tab. Instead
"Items=(Collection)" appears in the Control's tag and the designer eventually
"forgets" the ListItems that were entered.

How do I get the designer to add an asp:ListItem for each Item the way it
does with the standard DropDownList that's part of my control?

Thanks,
Steve

Author
27 May 2005 1:41 PM
Steve Trandahl
I now have this half working. I can persist the ListItems the way I want, but
if I'm interpreting this correctly, the parser isn't able to read it back in.
It thinks I need a property "asp:ListItem".

See http://blogs.aspadvice.com/jlovell/archive/2004/02/29/663.aspx

Show quoteHide quote
"Steve Trandahl" wrote:

> I have a composite control consisting of a DropdownList control and a button.
> I've included an Items property that returns a reference to the
> DropDownList's Items property, but when I add ListItems to it in Design mode,
> they aren't added as <asp:ListItem> in the HTML tab. Instead
> "Items=(Collection)" appears in the Control's tag and the designer eventually
> "forgets" the ListItems that were entered.
>
> How do I get the designer to add an asp:ListItem for each Item the way it
> does with the standard DropDownList that's part of my control?
>
> Thanks,
> Steve
Author
27 May 2005 8:50 PM
Steve Trandahl
I solved my problem by doing three more things:
1) using ParseChildrenAttribute(true, "Items") instead of
ParseChildrenAttribute(true) so it knew the information linked to the "Items"
property instead of an "asp:ListItem" property.
2) Made the Items property read only. When I didn't do that, I got a strange
error - '' could not be set on property "Items".
3) Executed this.EnsureChildControls() before attempting to read the Items
property of the DropDownList that was part of the composite control. This
caused the error "Items could not be initialized" which I assumed was a
parsing error, but wasn't. That became clear when I actually ran the project
and the debugger flagged that line with the error.

I hope this helps others who have these same problems. It's hard to find
information on this.

Steve

Show quoteHide quote
"Steve Trandahl" wrote:

> I now have this half working. I can persist the ListItems the way I want, but
> if I'm interpreting this correctly, the parser isn't able to read it back in.
> It thinks I need a property "asp:ListItem".
>
> See http://blogs.aspadvice.com/jlovell/archive/2004/02/29/663.aspx
>
> "Steve Trandahl" wrote:
>
> > I have a composite control consisting of a DropdownList control and a button.
> > I've included an Items property that returns a reference to the
> > DropDownList's Items property, but when I add ListItems to it in Design mode,
> > they aren't added as <asp:ListItem> in the HTML tab. Instead
> > "Items=(Collection)" appears in the Control's tag and the designer eventually
> > "forgets" the ListItems that were entered.
> >
> > How do I get the designer to add an asp:ListItem for each Item the way it
> > does with the standard DropDownList that's part of my control?
> >
> > Thanks,
> > Steve