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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I clear out a dropdownlist on a web form?

Status
Not open for further replies.

MzKitty

Programmer
Oct 28, 2003
254
0
0
US
I'm using vs2008 and am loading product dropdownlists when a user selects an order to use on a new ticket. I am loading the dropdownlists with the code below:
Dim Con As New System.Data.SqlClient.SqlConnection(strConnect)
Con.Open()
Try
strSql = "select t1.ProductID,t2.description from slorder t1 inner join Inproduc t2 " & _
"on t1.productID = t2.ProductID where t1.orderID = '" & strQJB & "' AND T1.ProductID <> 'SPCFRT' order by t1.productID;"
Dim PltCmd As New System.Data.SqlClient.SqlCommand(strSql, Con)
Dim rdr As System.Data.SqlClient.SqlDataReader = PltCmd.ExecuteReader()
' Populate the Control
While rdr.Read()
Dim newListItem As New ListItem()
newListItem.Text = rdr.GetString(0) + " " + rdr.GetString(1)
newListItem.Value = rdr.GetString(0) + " " + rdr.GetString(1)
dropProd1.Items.Add(newListItem)
dropProd2.Items.Add(newListItem)
dropProd3.Items.Add(newListItem)
dropProd4.Items.Add(newListItem)
dropProd5.Items.Add(newListItem)
dropProd6.Items.Add(newListItem)
dropProd7.Items.Add(newListItem)
dropProd8.Items.Add(newListItem)
dropProd9.Items.Add(newListItem)
dropProd10.Items.Add(newListItem)

End While
rdr.Close()
Con.Close()
My problem is when the user selects the wrong order and they go back and select the correct one, the products for both orders show on the dropdownlists. I need to clear the first order's products out before I load in the next orders. I have tried:

dropProd1.Items.Clear()

but it doesn't get rid of the products.

Thanks
Cathy
 
I assume you fixed this by now but when are you calling Items.Clear()?

 
Before it loads the dropdown box I was calling it. I did fix it, but I had to more code to clear out each row and then to add a new listitem. It works real slick now.

Dim maxcount As Integer
count = 1
maxcount = dropProd1.Items.Count

Do Until count > maxcount
dropProd1.Items.Clear()
count = count + 1
Loop
dropProd1.Items.Insert(0, New ListItem(" "))

Thanks
Cathy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top