Loading CheckBoxList

Discussion in 'ASP .Net' started by Andy G, Jun 23, 2006.

  1. Andy G

    Andy G Guest

    I have a checkBoxList control on a page that I want to load from a table.
    After it is loaded from the table I would like to check the certain boxes
    that are selected in the table.

    This is kindof what I have going here, I have a datareader loading the
    initial check list and then I am looping through a dataset to try to 'check'
    the boxes. I think I'll need a way to combine these two to make this work.

    Any help is greatly appreciated. If you have a website with info a link
    would be great too.

    Dim str As String = "SELECT PAY_MTHD_ID, PAY_MTHD FROM
    dbo.tblCONF_PAY_MTHD_LIST;"

    Dim myCmd As SqlCommand = New SqlCommand(str, conn)

    Dim drPay As SqlDataReader

    Dim dsPay As DataSet

    Dim i As Integer

    Try

    conn.Open()

    drPay = myCmd.ExecuteReader(CommandBehavior.CloseConnection)

    chkPayTypes.Items.Clear()

    chkPayTypes.DataValueField = "PAY_MTHD_ID"

    chkPayTypes.DataTextField = "PAY_MTHD"

    chkPayTypes.DataSource = drPay

    chkPayTypes.DataBind()



    Dim daPay As New SqlDataAdapter("SELECT CONF_ID, PAY_MTHD_ID, ALLOW " & _

    "FROM dbo.tblCONF_PMT_ALLOW " & _

    "WHERE CONF_ID = " & myID, conn)

    dsPay = New DataSet

    daPay.Fill(dsPay, "Payment")

    For i = 0 To dsPay.Tables("Payment").Rows.Count - 1

    Select Case dsPay.Tables("Payment").Rows(i).Item("PAY_MTHD_ID")

    Case 1

    If dsPay.Tables("Payment").Rows(i).Item("ALLOW") Then

    chkPayTypes.Items(0).Selected = True

    End If

    Case 2

    If dsPay.Tables("Payment").Rows(i).Item("ALLOW") Then

    chkPayTypes.Items(1).Selected = True

    End If

    Case 3

    If dsPay.Tables("Payment").Rows(i).Item("ALLOW") Then

    chkPayTypes.Items(2).Selected = True

    End If

    End Select

    Next

    chkPayTypes.DataSource = dsPay

    chkPayTypes.DataBind()
     
    Andy G, Jun 23, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JD
    Replies:
    5
    Views:
    11,832
    NetArchitect
    Aug 8, 2007
  2. Patrick.O.Ige
    Replies:
    5
    Views:
    19,286
    Patrick.O.Ige
    Jun 19, 2005
  3. David Segall
    Replies:
    2
    Views:
    460
    Thomas Kellerer
    Jan 2, 2007
  4. Replies:
    4
    Views:
    338
  5. edfialk
    Replies:
    0
    Views:
    210
    edfialk
    May 10, 2007
Loading...

Share This Page