views:

175

answers:

1

I have a checkboxlist in aspx as following.

<asp:CheckBoxList ID="new1" runat="server" RepeatColumns="3" RepeatDirection="Horizontal">
    <asp:ListItem>A</asp:ListItem>
    <asp:ListItem>B</asp:ListItem>
    <asp:ListItem>C</asp:ListItem>
    <asp:ListItem>D</asp:ListItem>
</asp:CheckBoxList>

In the table in sql server database, the data from this checkboxlist is stored in 1 field with comma delimiter.

e.g A,C,D or A,B,C,D.

now when i retrieve data i want to have only those checkboxes checked that are in that string in DB.

A: 

This not exactly what are you looking for. It's only standart db checkbox populate

Try
Dim cmd As SqlCommand = New SqlCommand("SELECT TOP 5 firstname,lastname,hiredate FROM EMPLOYEES", New SqlConnection("Server=localhost;Database=Northwind;Trusted_Connection=True;"))

cmd.Connection.Open()

Dim datareader As SqlDataReader = cmd.ExecuteReader()
chkBoxEx.DataSource = datareader
chkBoxEx.DataTextField = "firstname"

chkBoxEx.DataBind()

cmd.Connection.Close()
cmd.Connection.Dispose()
Catch ex As Exception
lblStatus.Text = ex.Message
End Try

You can get the values with substring from your field.

SELECT SUBSTRING(myField, 1, 1) AS A,SUBSTRING(myField, 3, 1) AS B from table
drorhan