Question Drop down list value change, depending on other value

iseeyou

New member
Joined
Feb 5, 2010
Messages
4
Programming Experience
5-10
Hi folks,

I have a drop down list that I have populated like this:

drpCountry.Items.Add(New ListItem("Country 1"))
drpCountry.Items.Add(New ListItem("Country 2"))
drpCountry.Items.Add(New ListItem("Country 3"))
drpCountry.Items.Add(New ListItem("Country 4"))
drpCountry.Items.Add(New ListItem("Country 5"))

I then have a textbox called txtCustomer where I type in a customer number. All customer numbers in country 1 starts with "1". All customer numbers in country 2 starts with "2" etc.

My problem is that I don´t know how the Drop Down List could change it´s value depending of the first character in my textbox called txtCustomer.

In the codebehind, I have tried this:

Protected Sub txtCustomer_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles txtCustomer.TextChanged
If Left(txtCustomer.Text, 1) = "1" Then
drpCountry.SelectedValue = "Country 1"
End If
If Left(txtCustomer.Text, 1) = "2" Then
drpCountry.SelectedValue = "Country 2"
End If
If Left(txtCustomer.Text, 1) = "3" Then
drpCountry.SelectedValue = "Country 3"
End If
End Sub

The selected row in the Drop Down should change depending of the first character into the textbox called txtCustomer.

This is probably rather simple for some of you guys, so I really hope that someone has an answer. :)

Thanks alot!!
 

Latest posts

Back
Top