This code shows how to choose multiple value from checkbox
mports System.Data.SqlClient Partial Class _Default Inherits System.Web.UI.Page Dim li As New ListItem ' create a new list item Dim i, j As Integer Dim arr As Array Dim str As String Dim dtr As SqlDataReader Dim con As New SqlConnection("") Dim cmd As New SqlCommand '1st method Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
For Each li In CheckBoxList1.Items
If li.Selected = True Then lbltext.Text = lbltext.Text & "," & li.Text End If Next li ' query =lbltext.text End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load lbltext.Text = "" 'put a label End Sub '2nd method Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click For i = 0 To CheckBoxList1.Items.Count - 1 If CheckBoxList1.Items(i).Selected = True Then lbltext.Text = lbltext.Text & "," & CheckBoxList1.Items(i).Text End If Next con.Open() cmd = New SqlCommand("insert into check1 values('" & lbltext.Text & "')", con) cmd.ExecuteNonQuery() con.Close() CheckBoxList1.SelectedIndex = -1 End Sub 'Back from the database Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click con.Open() cmd = New SqlCommand("select * from check1", con) dtr = cmd.ExecuteReader While (dtr.Read) str = dtr(0) End While con.Close() arr = Split(str, ",") For i = 0 To UBound(arr) ListBox1.Items.Add(arr(i)) For j = 0 To CheckBoxList1.Items.Count - 1 If CheckBoxList1.Items(j).Text = arr(i) Then CheckBoxList1.Items(j).Selected = True End If Next Next
End Sub End Class
|
No responses found. Be the first to respond and make money from revenue sharing program.
|