HtmlSelect control not showing ListItems

Discussion in 'ASP .Net' started by =?Utf-8?B?Sm9l?=, Dec 14, 2005.

  1. Hello All,

    I am populating an HtmlSelect control's Items property with four list items.
    The HtmlSelect control is contained in a user control which is dropped into
    a placeholder on the web form. When the page is rendered, the control is
    empty. Here is the code:

    In the web form:

    Dim UControl As AugmentedDropDownList =
    CType(LoadControl("../UserControls/AugmentedDropDownList.ascx"),
    AugmentedDropDownList)

    UControl.PopulateDropDownList(Control.Attributes("name").Value, DropDownNode)

    plcContent.Controls.Add(UControl)

    and in the user control:

    Public Sub PopulateDropDownList(ByVal ListCaption As String, ByVal
    ListItems As XmlNode)
    Label1.Text = ListCaption
    SelectList = New HtmlSelect
    SelectList.Name = ListCaption
    For Each Item As XmlNode In ListItems.SelectNodes("Items/Item")
    Dim li As New ListItem
    li.Value = Item.Attributes("id").Value
    li.Text = Item.Attributes("value").Value
    SelectList.Items.Add(li)
    Next
    SelectList.ID = ListItems.Attributes("id").Value
    End Sub

    Can anyone see what I'm missing?

    TIA,
    --
    Joe

    VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
    =?Utf-8?B?Sm9l?=, Dec 14, 2005
    #1
    1. Advertising

  2. I have to bind the Items property to the HtmlSelect control?
    --
    Joe

    VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


    "David Branch" wrote:

    > call the databind method...
    >
    > "Joe" wrote:
    >
    > > Hello All,
    > >
    > > I am populating an HtmlSelect control's Items property with four list items.
    > > The HtmlSelect control is contained in a user control which is dropped into
    > > a placeholder on the web form. When the page is rendered, the control is
    > > empty. Here is the code:
    > >
    > > In the web form:
    > >
    > > Dim UControl As AugmentedDropDownList =
    > > CType(LoadControl("../UserControls/AugmentedDropDownList.ascx"),
    > > AugmentedDropDownList)
    > >
    > > UControl.PopulateDropDownList(Control.Attributes("name").Value, DropDownNode)
    > >
    > > plcContent.Controls.Add(UControl)
    > >
    > > and in the user control:
    > >
    > > Public Sub PopulateDropDownList(ByVal ListCaption As String, ByVal
    > > ListItems As XmlNode)
    > > Label1.Text = ListCaption
    > > SelectList = New HtmlSelect
    > > SelectList.Name = ListCaption
    > > For Each Item As XmlNode In ListItems.SelectNodes("Items/Item")
    > > Dim li As New ListItem
    > > li.Value = Item.Attributes("id").Value
    > > li.Text = Item.Attributes("value").Value
    > > SelectList.Items.Add(li)
    > > Next
    > > SelectList.ID = ListItems.Attributes("id").Value
    > > End Sub
    > >
    > > Can anyone see what I'm missing?
    > >
    > > TIA,
    > > --
    > > Joe
    > >
    > > VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
    =?Utf-8?B?Sm9l?=, Dec 14, 2005
    #2
    1. Advertising

  3. call the databind method...

    "Joe" wrote:

    > Hello All,
    >
    > I am populating an HtmlSelect control's Items property with four list items.
    > The HtmlSelect control is contained in a user control which is dropped into
    > a placeholder on the web form. When the page is rendered, the control is
    > empty. Here is the code:
    >
    > In the web form:
    >
    > Dim UControl As AugmentedDropDownList =
    > CType(LoadControl("../UserControls/AugmentedDropDownList.ascx"),
    > AugmentedDropDownList)
    >
    > UControl.PopulateDropDownList(Control.Attributes("name").Value, DropDownNode)
    >
    > plcContent.Controls.Add(UControl)
    >
    > and in the user control:
    >
    > Public Sub PopulateDropDownList(ByVal ListCaption As String, ByVal
    > ListItems As XmlNode)
    > Label1.Text = ListCaption
    > SelectList = New HtmlSelect
    > SelectList.Name = ListCaption
    > For Each Item As XmlNode In ListItems.SelectNodes("Items/Item")
    > Dim li As New ListItem
    > li.Value = Item.Attributes("id").Value
    > li.Text = Item.Attributes("value").Value
    > SelectList.Items.Add(li)
    > Next
    > SelectList.ID = ListItems.Attributes("id").Value
    > End Sub
    >
    > Can anyone see what I'm missing?
    >
    > TIA,
    > --
    > Joe
    >
    > VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
    =?Utf-8?B?RGF2aWQgQnJhbmNo?=, Dec 14, 2005
    #3
  4. Sorry about the answer i give you

    You must add the control the the page.

    Page.Controls.Add(SelectList)


    David

    "Joe" wrote:

    > I have to bind the Items property to the HtmlSelect control?
    > --
    > Joe
    >
    > VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
    >
    >
    > "David Branch" wrote:
    >
    > > call the databind method...
    > >
    > > "Joe" wrote:
    > >
    > > > Hello All,
    > > >
    > > > I am populating an HtmlSelect control's Items property with four list items.
    > > > The HtmlSelect control is contained in a user control which is dropped into
    > > > a placeholder on the web form. When the page is rendered, the control is
    > > > empty. Here is the code:
    > > >
    > > > In the web form:
    > > >
    > > > Dim UControl As AugmentedDropDownList =
    > > > CType(LoadControl("../UserControls/AugmentedDropDownList.ascx"),
    > > > AugmentedDropDownList)
    > > >
    > > > UControl.PopulateDropDownList(Control.Attributes("name").Value, DropDownNode)
    > > >
    > > > plcContent.Controls.Add(UControl)
    > > >
    > > > and in the user control:
    > > >
    > > > Public Sub PopulateDropDownList(ByVal ListCaption As String, ByVal
    > > > ListItems As XmlNode)
    > > > Label1.Text = ListCaption
    > > > SelectList = New HtmlSelect
    > > > SelectList.Name = ListCaption
    > > > For Each Item As XmlNode In ListItems.SelectNodes("Items/Item")
    > > > Dim li As New ListItem
    > > > li.Value = Item.Attributes("id").Value
    > > > li.Text = Item.Attributes("value").Value
    > > > SelectList.Items.Add(li)
    > > > Next
    > > > SelectList.ID = ListItems.Attributes("id").Value
    > > > End Sub
    > > >
    > > > Can anyone see what I'm missing?
    > > >
    > > > TIA,
    > > > --
    > > > Joe
    > > >
    > > > VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
    =?Utf-8?B?RGF2aWQgQnJhbmNo?=, Dec 14, 2005
    #4
    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. Suhail A, Salman
    Replies:
    0
    Views:
    353
    Suhail A, Salman
    Aug 13, 2003
  2. =?Utf-8?B?Wm9vZG9y?=
    Replies:
    0
    Views:
    398
    =?Utf-8?B?Wm9vZG9y?=
    Nov 15, 2005
  3. Tom
    Replies:
    2
    Views:
    418
  4. Alex

    HtmlSelect or ListBox control

    Alex, Sep 12, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    127
  5. Steve Trandahl

    DropDownList in composite control not saving ListItems

    Steve Trandahl, May 26, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    284
    Steve Trandahl
    May 27, 2005
Loading...

Share This Page