Cannot use ListItems when inheriting from DropDownList

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nathan Sokalski

    Cannot use ListItems when inheriting from DropDownList

    I am creating a control in which I inherit from the DropDownList. The only
    method that I override is RenderContents. Here is my basic code:

    Public Class StatesDropDownL ist : Inherits DropDownList

    Protected Overrides Sub RenderContents( ByVal writer As
    System.Web.UI.H tmlTextWriter)
    'I add several items to the Items property here using Me.Items.Add()
    MyBase.RenderCo ntents(writer)
    End Sub

    End Class

    However, when I attempt to add ListItems declaratively (by placing
    <asp:ListItem/tags between the opening and closing tags for my control),
    Visual Studio 2005 tells me "Element 'ListItem' is not a known element." I
    am inheriting from DropDownList, and DropDownList works fine even in the
    same Page, so shouldn't my control allow <asp:ListItem/tags as well? Any
    help would be appreciated. Thanks.
    --
    Nathan Sokalski
    njsokalski@hotm ail.com
    有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。



  • PJ on Development

    #2
    Re: Cannot use ListItems when inheriting from DropDownList

    Hi, Nathan.

    You need to specify a ControlBuilder.

    Gain technical skills through documentation and training, earn certifications and connect with the community


    The ControlBuilder object must know how to create the items.

    Regards,

    Paulo Santos


    On Oct 16, 9:36 pm, "Nathan Sokalski" <njsokal...@hot mail.comwrote:
    I am creating a control in which I inherit from the DropDownList. The only
    method that I override is RenderContents. Here is my basic code:
    >
    Public Class StatesDropDownL ist : Inherits DropDownList
    >
      Protected Overrides Sub RenderContents( ByVal writer As
    System.Web.UI.H tmlTextWriter)
       'I add several items to the Items property here using Me.Items.Add()
       MyBase.RenderCo ntents(writer)
      End Sub
    >
    End Class
    >
    However, when I attempt to add ListItems declaratively (by placing
    <asp:ListItem/tags between the opening and closing tags for my control),
    Visual Studio 2005 tells me "Element 'ListItem' is not a known element." I
    am inheriting from DropDownList, and DropDownList works fine even in the
    same Page, so shouldn't my control allow <asp:ListItem/tags as well? Any
    help would be appreciated. Thanks.
    --
    Nathan Sokalski
    njsokal...@hotm ail.comhttp://www.nathansokal ski.com/

    Comment

    Working...