Groups | Blog | Home
all groups > asp.net webcontrols > may 2005 >

asp.net webcontrols : DropDownList in composite control not saving ListItems


Steve Trandahl
5/26/2005 10:27:01 AM
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 Trandahl
5/27/2005 6:41:07 AM
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

[quoted text, click to view]
Steve Trandahl
5/27/2005 1:50:32 PM
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

[quoted text, click to view]
AddThis Social Bookmark Button