Function CheckBoxListDataTable()
Dim objConn As OleDbConnection
Dim dtAdapter As OleDbDataAdapter
Dim dt As New DataTable
Dim strConnString As String
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& _
Server.MapPath("database/mydatabase.mdb")&";"
objConn = New OleDbConnection(strConnString)
objConn.Open()
Dim strSQL As String
strSQL = "SELECT * FROM country"
dtAdapter = New OleDbDataAdapter(strSQL, objConn)
dtAdapter.Fill(dt)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
'*** CheckBoxList ***'
With Me.myCBoxList1
.DataSource = dt
.DataTextField = "CountryName"
.DataValueField = "CountryCode"
.DataBind()
End With
'*** Default Value ***'
myCBoxList1.SelectedIndex = myCBoxList1.Items.IndexOf(myCBoxList1.Items.FindByValue("TH")) '*** By DataValueField ***'
'myCBoxList1.SelectedIndex = myCBoxList1.Items.IndexOf(myCBoxList1.Items.FindByText("Thailand")) '*** By DataTextField ***'