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!

Loop DropDownList..? 1

Status
Not open for further replies.

kenjoswe

Technical User
Sep 19, 2000
327
SE
Hi all,

I have five dropdownlists on a form.
I would like create a loop so that I can reduce the code. Something like:

Dim DDList As DropDownList
For intCount = 1 To 5
With DDList(intCount)
.DataSource = objDS.Tables(1)
.DataTextField = ("myText")
.DataValueField = ("myValue")
.DataBind()
End With
Next

/Kent J.
 
You can keep 5 DropDownLists,DataTables,TextFields, and Value fields in
4 different arraylists.

Within a loop you need to typecast the appropriately while assigning

Dim alLists As New ArrayList()
al.Add(dropList1)
al.Add(dropList22)
Dim alDataTab As New ArrayList()
'similarly add 5 datatables
Dim alValFields As New ArrayList()
'similarly add 5 value fields as strings
Dim alTextFields As New ArrayList()
'similarly add 5 text fields as strings
Dim dd1 As New DropDownList()
Dim i As Integer = 0
While (i < 2)

dd1 = New DropDownList()
dd1 = CType(alLists(i), DropDownList)
dd1.DataSource = CType(alDataTab(i), DataTable)

dd1.DataTextField = Convert.ToString(alTextFields(i))
dd1.DataBind()
i = i + 1
End While
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top