Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic DropDown List Issues

Status
Not open for further replies.

level1

Programmer
Apr 16, 2002
60
GB
I have a static multiselect list-box tbl1 which contains values.

i m selecting several values i.e value1 and value2 and after clicking a button i want based on these selected values to create Dynamically (2) drop down boxes and append to them the values of my previous selection.

So for example if on my listbox select 1 and 2 i want to create 2 dropdowns and each of them contain values 1 and 2 accordingly.

I use the following code which assumes that tbl1 is a listbox on my form:

Dim drpbox As DropDownList

If tbl1.SelectedIndex > -1 Then
For ctr = 0 To tbl1.Items.Count() - 1
If tbl1.Items(ctr).Selected Then
drpbox = New DropDownList
drpbox.ID = "DrpBoxTbl" & ctr
drpbox.SelectedIndex = -1
drpbox.Items.Add(tbl1.SelectedItem)
plhProductFields.Controls.Add(drpbox)
End If
Next

This results the following HTML:

<select name="DrpBoxTbl0" id="DrpBoxTbl0">
<option value="Value1">Value1</option>
<select name="DrpBoxTbl1" id="DrpBoxTbl1">
<option value="Value2">Value2</option>


What i hope to achieve is the following

<select name="DrpBoxTbl0" id="DrpBoxTbl0">
<option value="Value1">Value1</option>
<option value="Value2">Value2</option>
<select name="DrpBoxTbl1" id="DrpBoxTbl1">
<option value="Value1">Value1</option>
<option value="Value2">Value2</option>

Can you please help?
 
plhProductFields is a Placeholder object already on the form.
 
This worked for anyone interested after 8 hours hammering my brain.


Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
Dim ctr As Integer
Dim i As Integer

Dim drpbox As New DropDownList
Dim LitLabel As LiteralControl
Dim MyArray As New ArrayList

MyArray.Add("[Select Field]")

Dim SQLstr As String
Label2.Text = ""
i = 0
If tbl1.SelectedIndex > -1 Then
For ctr = 0 To tbl1.Items.Count() - 1
If tbl1.Items(ctr).Selected Then
MyArray.Add(tbl1.Items(ctr).ToString)
i += 1
End If
Next
End If
For ctr = 0 To i - 1
LitLabel = New LiteralControl
LitLabel.Text = "<p>Criteria " & ctr & ": "
LitLabel.ID = "txtProduct" & ctr
plhProductFields.Controls.Add(LitLabel)

drpbox = New DropDownList
drpbox.ID = "DrpBox" & ctr
drpbox.DataSource = MyArray
drpbox.DataBind()
plhProductFields.Controls.Add(drpbox)
Next

End Sub



output


<div style="Z-INDEX: 110; LEFT: 10px; POSITION: absolute; TOP: 500px; BACKGROUND-COLOR: yellow">
<p>Criteria 0: <select name="DrpBox0" id="DrpBox0">
<option value="[Select Field]">[Select Field]</option>
<option value="CREATED">CREATED</option>
<option value="HW_UUID">HW_UUID</option>

</select><p>Criteria 1: <select name="DrpBox1" id="DrpBox1">
<option value="[Select Field]">[Select Field]</option>
<option value="CREATED">CREATED</option>
<option value="HW_UUID">HW_UUID</option>

</select>
</div>

Make sure you please the placeholder (plhProductFields) within a Div to be able to possition it properly on the form.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top