-
Loops and drpLists
I have a sub looking like this:
Code:
Protected Sub bindMaterialer1()
'Denne fuktion henter samtlige kunder fra databasen
Dim strCn As String = "Provider=Microsoft.jet.oledb.4.0;"
strCn += "Data Source=" & Server.MapPath("priser.mdb") & ";"
Dim cn As OleDbConnection = New OleDbConnection(strCn)
Dim cmdText As String = "Select Id as matId, Materiale FROM MedieMatNy Order By Id"
Dim cmd As OleDbCommand = New OleDbCommand(cmdText, cn)
cmd.Connection.Open()
mat1.DataSource = cmd.ExecuteReader()
mat1.DataValueField = "matId"
mat1.DataTextField = "Materiale"
mat1.DataBind()
cmd.Connection.Close()
cmd.Connection.Open()
mat2.DataSource = cmd.ExecuteReader()
mat2.DataValueField = "matId"
mat2.DataTextField = "Materiale"
mat2.DataBind()
cmd.Connection.Close()
...
cmd.Connection.Open()
mat10.DataSource = cmd.ExecuteReader()
mat10.DataValueField = "matId"
mat10.DataTextField = "Materiale"
mat10.DataBind()
cmd.Connection.Close()
End Sub
I have 10 drpList, isn't it possible using a loop instead of writing the code 10 times?
-
Unfortunately no since control arrays no longer exsist in the .NET environment.
There may be a way, but I dunno what it is.