Dropdown List Help

dbernie41

New member
Joined
Apr 27, 2005
Messages
1
Programming Experience
1-3
Alright. I have 3 dropdown lists and then I have an integer variable. For now,l ets just say the variable equals 15.

The goal at the end is to have the values selected in the 3 dropdown lists equal 15.

All 3 lists are selectable and I want it to be like when the first list is "dropped" I want the values to be 0-15. Then lets say a '7' is selected. Then I want the other 2 DDLs to show values of 1-8. And once a second value is selected, lets say '5' then the 3rd DDL would be 1-3.

I hope I made this clear enough. How do I do this?
 
This would work for WinForms but I'm not 100% sure for WebForms.

In the SelectedIndexChanged event handler for the first list you need to clear the second list an repopulate it with just the valid options using Items.Add() or Items.AddRange(). Alternatively you could just add or remove the required item values each time rather than clearing the whole list. You can then do the same for the third list in the SelectedIndexChanged event handler of the second list.
 
Probably something like:
for DDL1
PHP:
PrivateSub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
 
DropDownList2.Items.Clear()
 
DropDownList3.Items.Clear()
 
Dim q AsInteger = CType(DropDownList1.SelectedItem.ToString, Integer)
 
Dim w AsInteger = 15 - q
 
Dim i AsInteger
 
For i = 1 To w
 
DropDownList2.Items.Add(i)
 
DropDownList3.Items.Add(i)
 
Next
 
EndSub


i guess you know how to fill these DDLs on load !?

PHP:
Private Sub Page_Load(ByVal sender As System.Object, _ByVal e As System.EventArgs) Handles MyBase.Load
 
Dim i As Integer 
 
For i = 1 To 15
 
DropDownList1.Items.Add(i)
 
DropDownList2.Items.Add(i)
 
DropDownList3.Items.Add(i)
 
Next
 
End Sub



Cheers ;)
 
Last edited:
Back
Top