Results 1 to 2 of 2

Thread: Loops and drpLists

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049

    Question 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?

  2. #2
    Addicted Member rdove's Avatar
    Join Date
    Dec 2002
    Location
    Indianapolis
    Posts
    251
    Unfortunately no since control arrays no longer exsist in the .NET environment.

    There may be a way, but I dunno what it is.
    ~Ryan





    Have I helped you? Please Rate my posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width