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. Advertisements

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. Francois Verbeeck
    Replies:
    0
    Views:
    1,993
    Francois Verbeeck
    Jun 24, 2003
  2. Ignacio Martinez

    Re: checkboxlist control

    Ignacio Martinez, Jun 30, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    529
    Ignacio Martinez
    Jun 30, 2003
  3. JD
    Replies:
    5
    Views:
    12,458
    NetArchitect
    Aug 8, 2007
  4. Patrick.O.Ige
    Replies:
    5
    Views:
    19,779
    Patrick.O.Ige
    Jun 19, 2005
  5. David Segall
    Replies:
    2
    Views:
    660
    Thomas Kellerer
    Jan 2, 2007
  6. Replies:
    4
    Views:
    520
  7. edfialk
    Replies:
    0
    Views:
    347
    edfialk
    May 10, 2007
  8. ofir
    Replies:
    0
    Views:
    290
Loading...