Loading CheckBoxList

A

Andy G

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()
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top