Newbie Qs: Dynamic dropdownlist does not show

A

AlecL

Hi there,

I am trying to dynamically add rows of dropdownboxes the number of
which is picked by another dropdown box and although the code is
being processed would not add dropdownboxes to a div.

Here is the code:

Protected Sub ddlMentHowManyChildren_SelectedIndexChanged(ByVal sender
As Object, ByVal e As System.EventArgs)
If ddlMentHaveChildren.SelectedValue <> "" Then
mentChildInfo.Visible = True
ddlMentHowManyChildren.Visible = False
Dim i As Integer
Dim j As Integer = Val(ddlMentHaveChildren.SelectedValue)
For i = 1 To j
Dim ctrlDropDown1 = New
System.Web.UI.WebControls.DropDownList
Dim ctrlDropDown2 = New
System.Web.UI.WebControls.DropDownList
ctrlDropDown1.ID = "ddlMentChildGender" & i
ctrlDropDown2.ID = "ddlMentChildAge" & i
Dim listItem1 As New System.Web.UI.WebControls.ListItem
Dim listItem2 As New System.Web.UI.WebControls.ListItem
Dim IntAge As Integer
For IntAge = 1 To 50
ctrlDropDown2.Items.Add(IntAge.ToString)

Next
Me.mentChildInfo.Controls.Add(ctrlDropDown1)
Me.mentChildInfo.Controls.Add(ctrlDropDown2)
Next
End If
End Sub

In the above code mentChildInfo is the div that is set to runat
="server" and ddlMentHowManyChildren is the ddl which provides the
number of rows.

Any help would be appreciated.

Alec
 
G

Guest

Hi there,

I am trying to dynamically add rows of dropdownboxes the number of
which is picked by another dropdown box and although the code is
being processed would not add dropdownboxes to a div.

Here is the code:

Protected Sub ddlMentHowManyChildren_SelectedIndexChanged(ByVal sender
As Object, ByVal e As System.EventArgs)
If ddlMentHaveChildren.SelectedValue <> "" Then
mentChildInfo.Visible = True
ddlMentHowManyChildren.Visible = False
Dim i As Integer
Dim j As Integer = Val(ddlMentHaveChildren.SelectedValue)
For i = 1 To j

j = ?

I see that it is equal to the ddlMentHaveChildren.SelectedValue, but
are you sure that it's more than 1?

Dim ctrlDropDown1 = New
System.Web.UI.WebControls.DropDownList
Dim ctrlDropDown2 = New
System.Web.UI.WebControls.DropDownList
ctrlDropDown1.ID = "ddlMentChildGender" & i
ctrlDropDown2.ID = "ddlMentChildAge" & i
Dim listItem1 As New System.Web.UI.WebControls.ListItem
Dim listItem2 As New System.Web.UI.WebControls.ListItem
Dim IntAge As Integer
For IntAge = 1 To 50
ctrlDropDown2.Items.Add(IntAge.ToString)

Next

You don't populate the ctrlDropDown1. The code above added 50 rows to
the ctrlDropDown2 Control only.

What listItem1 and listItem2 doing here?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top