DropDownList in composite control not saving ListItems

Discussion in 'ASP .Net Web Controls' started by Steve Trandahl, May 26, 2005.

  1. 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
     
    Steve Trandahl, May 26, 2005
    #1
    1. Advertising

  2. 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
     
    Steve Trandahl, May 27, 2005
    #2
    1. Advertising

  3. 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

    "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
     
    Steve Trandahl, May 27, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Doug
    Replies:
    7
    Views:
    5,481
    Scott G.
    Aug 2, 2004
  2. Jeff
    Replies:
    1
    Views:
    6,531
    Bruce Barker
    Mar 18, 2005
  3. Lisa

    Exposing ListItems in Composite Control

    Lisa, Sep 8, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    120
  4. Chad
    Replies:
    0
    Views:
    236
  5. Lisa

    Exposing ListItems in Composite Control

    Lisa, Sep 9, 2004, in forum: ASP .Net Web Controls
    Replies:
    5
    Views:
    234
    Alessandro Zifiglio
    Sep 23, 2004
Loading...

Share This Page