Inserting checkbox values into one field

Reply

Join Date: May 2009
Posts: 4
Reputation: ebosysindia is an unknown quantity at this point 
Solved Threads: 0
ebosysindia ebosysindia is offline Offline
Newbie Poster

Inserting checkbox values into one field

 
0
  #1
May 4th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 182
Reputation: Kusno is an unknown quantity at this point 
Solved Threads: 15
Kusno's Avatar
Kusno Kusno is offline Offline
Junior Poster

Re: Inserting checkbox values into one field

 
0
  #2
May 7th, 2009
Hi ebosysindia,
Please use CheckBoxList control.

and to check which item is selected :

  1. Dim V As String = ""
  2. Dim I As SByte
  3. For i = 0 To CheckBoxList1.Items.Count - 1
  4. If CheckBoxList1.Items(I).Selected = True Then
  5. If V = "" Then
  6. V = CheckBoxList1.Items(I).Value
  7. Else
  8. V = V & "," & CheckBoxList1.Items(I).Value
  9. End If
  10. End If
  11. Next
  12. TextBox1.Text = V

or if you want to insert the items into database
  1. Dim V As String = ""
  2. Dim I As SByte
  3. Dim SQL As String = ""
  4. Dim SQLList As New StringBuilder
  5.  
  6. For i = 0 To CheckBoxList1.Items.Count - 1
  7. If CheckBoxList1.Items(I).Selected = True Then
  8. SQL = "INSERT INTO CUSTOMER VALUES('0001','" & CheckBoxList1.Items(I).Value & "')" & vbCrLf
  9. SQLList.Append(SQL)
  10. End If
  11. Next
  12. TextBox1.Text = SQLList.ToString
NEVER NEVER NEVER GIVE UP
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 4
Reputation: ebosysindia is an unknown quantity at this point 
Solved Threads: 0
ebosysindia ebosysindia is offline Offline
Newbie Poster

Re: Inserting checkbox values into one field

 
0
  #3
May 7th, 2009
Originally Posted by Kusno View Post
Hi ebosysindia,
Please use CheckBoxList control.

and to check which item is selected :

  1. Dim V As String = ""
  2. Dim I As SByte
  3. For i = 0 To CheckBoxList1.Items.Count - 1
  4. If CheckBoxList1.Items(I).Selected = True Then
  5. If V = "" Then
  6. V = CheckBoxList1.Items(I).Value
  7. Else
  8. V = V & "," & CheckBoxList1.Items(I).Value
  9. End If
  10. End If
  11. Next
  12. TextBox1.Text = V

or if you want to insert the items into database
  1. Dim V As String = ""
  2. Dim I As SByte
  3. Dim SQL As String = ""
  4. Dim SQLList As New StringBuilder
  5.  
  6. For i = 0 To CheckBoxList1.Items.Count - 1
  7. If CheckBoxList1.Items(I).Selected = True Then
  8. SQL = "INSERT INTO CUSTOMER VALUES('0001','" & CheckBoxList1.Items(I).Value & "')" & vbCrLf
  9. SQLList.Append(SQL)
  10. End If
  11. Next
  12. TextBox1.Text = SQLList.ToString
Hello Dear,

Thanks for giving asnwer
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1049 | Replies: 2
Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC