hi

I have a checkboxes on my page (.aspx) like

checkbox1 - item1
checkbox2 - item2
checkbox3 - item3
etc

what i want is that when a user selects certain checkboxes
they should be inserted into a table called
customer which has fields (customer id and actions)

the data should be inserted as

customerid actions
1 item1,item2,item3
2 item1,item3
3 etc..

i.e all the values should be inserted into database into one field separated by commas.

Thanks

Hi ebosysindia,
Please use CheckBoxList control.

and to check which item is selected :

Dim V As String = ""
        Dim I As SByte
        For i = 0 To CheckBoxList1.Items.Count - 1
            If CheckBoxList1.Items(I).Selected = True Then
                If V = "" Then
                    V = CheckBoxList1.Items(I).Value
                Else
                    V = V & "," & CheckBoxList1.Items(I).Value
                End If
            End If
        Next
        TextBox1.Text = V

or if you want to insert the items into database

Dim V As String = ""
        Dim I As SByte
        Dim SQL As String = ""
        Dim SQLList As New StringBuilder

        For i = 0 To CheckBoxList1.Items.Count - 1
            If CheckBoxList1.Items(I).Selected = True Then
                SQL = "INSERT INTO CUSTOMER VALUES('0001','" & CheckBoxList1.Items(I).Value & "')" & vbCrLf
                SQLList.Append(SQL)
            End If
        Next
        TextBox1.Text = SQLList.ToString

Hi ebosysindia,
Please use CheckBoxList control.

and to check which item is selected :

Dim V As String = ""
        Dim I As SByte
        For i = 0 To CheckBoxList1.Items.Count - 1
            If CheckBoxList1.Items(I).Selected = True Then
                If V = "" Then
                    V = CheckBoxList1.Items(I).Value
                Else
                    V = V & "," & CheckBoxList1.Items(I).Value
                End If
            End If
        Next
        TextBox1.Text = V

or if you want to insert the items into database

Dim V As String = ""
        Dim I As SByte
        Dim SQL As String = ""
        Dim SQLList As New StringBuilder

        For i = 0 To CheckBoxList1.Items.Count - 1
            If CheckBoxList1.Items(I).Selected = True Then
                SQL = "INSERT INTO CUSTOMER VALUES('0001','" & CheckBoxList1.Items(I).Value & "')" & vbCrLf
                SQLList.Append(SQL)
            End If
        Next
        TextBox1.Text = SQLList.ToString

Hello Dear,

Thanks for giving asnwer

Can we code like that :

SQL = "INSERT INTO "& something.text &" VALUES('0001','" & CheckBoxList1.Items(I).Value & "')" & vbCrLf 
SQLList.Append(SQL)
This article has been dead for over six months. Start a new discussion instead.