I have the following code which populates a checkbox list control with selected values from a table. This works perfectly fine.
What I now need to do is, if a user selects/deselects a checkbox I want to save these changes to the table.
Help please.
What I now need to do is, if a user selects/deselects a checkbox I want to save these changes to the table.
Help please.
Code:
If Not IsPostBack Then
Dim strConnString As String = ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString
Dim objConn As New SqlConnection(strConnString)
Dim objcmd As New SqlCommand()
objcmd.CommandType = CommandType.StoredProcedure
objcmd.CommandText = "spGetRoomFeatures"
objcmd.Connection = objConn
objConn.Open()
CheckBoxList1.DataSource = objcmd.ExecuteReader(CommandBehavior.CloseConnection)
CheckBoxList1.DataBind()
objcmd = New SqlCommand()
objcmd.CommandType = CommandType.StoredProcedure
objcmd.CommandText = "spGetSelectedFeatures"
objcmd.Parameters.Add("@RoomID", SqlDbType.Int).Value = 1
objcmd.Connection = objConn
objConn.Open()
Dim objReader As SqlDataReader = objCmd.ExecuteReader()
While objReader.Read()
Dim currentCheckBox As ListItem = CheckBoxList1.Items.FindByValue(objReader("feature").ToString())
If currentCheckBox IsNot Nothing Then
currentCheckBox.Selected = True
End If
End While
End If