>>>Private Sub Page_PreRenderComplete(sender As Object, e As System.EventArgs) Handles Me.PreRenderComplete >>> >>> Dim Basecase_ck As CheckBox = Basecase_CheckBox >>> Dim Scenario1_ck As CheckBox = Scenario1_CheckBox >>> Dim Scenario2_ck As CheckBox = Scenario2_CheckBox >>> Dim Scenario3_ck As CheckBox = Scenario3_CheckBox >>> Dim Scenario4_ck As CheckBox = Scenario4_CheckBox >>> Dim Scenario5_ck As CheckBox = Scenario5_CheckBox >>> Dim Scenario6_ck As CheckBox = Scenario6_CheckBox >>> >>> If Not User.IsInRole("CanEditBasecase") Then >>> Basecase_ck.Enabled = False >>> End If >>> If Not User.IsInRole("CanEditScenario1") Then >>> Scenario1_ck.Enabled = False >>> End If >>> If Not User.IsInRole("CanEditScenario2") Then >>> Scenario2_ck.Enabled = False >>> End If >>> If Not User.IsInRole("CanEditScenario3") Then >>> Scenario3_ck.Enabled = False >>> End If >>> If Not User.IsInRole("CanEditScenario4") Then >>> Scenario4_ck.Enabled = False >>> End If >>> If Not User.IsInRole("CanEditScenario5") Then >>> Scenario5_ck.Enabled = False >>> End If >>> If Not User.IsInRole("CanEditScenario6") Then >>> Scenario6_ck.Enabled = False >>> End If >>> >>> Dim oConn As New SqlConnection(ConfigurationManager.ConnectionStrings("sqlRTPConnectionString").ConnectionString) >>> Dim oCommand As New SqlClient.SqlCommand("SELECT rtp_id, [basecase], scenario1, scenario2, scenario3, scenario4, scenario5, scenario6 FROM rtp_projects WHERE rtp_id = @rtp_id", oConn) >>> oConn.Open() >>> oCommand.Parameters.AddWithValue("@rtp_id", FormView1.SelectedValue) >>> Dim oReader As SqlDataReader = oCommand.ExecuteReader >>> oReader.Read() >>> Basecase_ck.Checked = oReader("Basecase") >>> Scenario1_ck.Checked = oReader("Scenario1") >>> Scenario2_ck.Checked = oReader("Scenario2") >>> Scenario3_ck.Checked = oReader("Scenario3") >>> Scenario4_ck.Checked = oReader("Scenario4") >>> Scenario5_ck.Checked = oReader("Scenario5") >>> Scenario6_ck.Checked = oReader("Scenario6") >>> >>> oReader.Close() >>> oCommand.Dispose() >>> oConn.Close() >>> End Sub >>>>>>and updated with this:
>>> Public Sub SaveCheckBoxes(sender As Object, e As EventArgs) >>> Dim oConn As New SqlConnection(ConfigurationManager.ConnectionStrings("sqlRTPConnectionString").ConnectionString) >>> Dim oCommand As New SqlClient.SqlCommand("", oConn) >>> oConn.Open() >>> >>> Select Case sender.ID.ToString >>> Case "Basecase_CheckBox" >>> oCommand.CommandText = "UPDATE [rtp_projects] SET [basecase] = @basecase WHERE rtp_id = @rtp_id" >>> oCommand.Parameters.AddWithValue("@basecase", sender.Checked) >>> oCommand.Parameters.AddWithValue("@RTP_ID", FormView1.SelectedValue) >>> Case "Scenario1_CheckBox" >>> oCommand.CommandText = "UPDATE [rtp_projects] SET [Scenario1] = @Scenario1 WHERE rtp_id = @rtp_id" >>> oCommand.Parameters.AddWithValue("@Scenario1", sender.Checked) >>> oCommand.Parameters.AddWithValue("@RTP_ID", FormView1.SelectedValue) >>> Case "Scenario2_CheckBox" >>> oCommand.CommandText = "UPDATE [rtp_projects] SET [Scenario2] = @Scenario2 WHERE rtp_id = @rtp_id" >>> oCommand.Parameters.AddWithValue("@Scenario2", sender.Checked) >>> oCommand.Parameters.AddWithValue("@RTP_ID", FormView1.SelectedValue) >>> Case "Scenario3_CheckBox" >>> oCommand.CommandText = "UPDATE [rtp_projects] SET [Scenario3] = @Scenario3 WHERE rtp_id = @rtp_id" >>> oCommand.Parameters.AddWithValue("@Scenario3", sender.Checked) >>> oCommand.Parameters.AddWithValue("@RTP_ID", FormView1.SelectedValue) >>> Case "Scenario4_CheckBox" >>> oCommand.CommandText = "UPDATE [rtp_projects] SET [Scenario4] = @Scenario4 WHERE rtp_id = @rtp_id" >>> oCommand.Parameters.AddWithValue("@Scenario4", sender.Checked) >>> oCommand.Parameters.AddWithValue("@RTP_ID", FormView1.SelectedValue) >>> Case "Scenario5_CheckBox" >>> oCommand.CommandText = "UPDATE [rtp_projects] SET [Scenario5] = @Scenario5 WHERE rtp_id = @rtp_id" >>> oCommand.Parameters.AddWithValue("@Scenario5", sender.Checked) >>> oCommand.Parameters.AddWithValue("@RTP_ID", FormView1.SelectedValue) >>> Case "Scenario6_CheckBox" >>> oCommand.CommandText = "UPDATE [rtp_projects] SET [Scenario6] = @Scenario6 WHERE rtp_id = @rtp_id" >>> oCommand.Parameters.AddWithValue("@Scenario6", sender.Checked) >>> oCommand.Parameters.AddWithValue("@RTP_ID", FormView1.SelectedValue) >>> >>> End Select >>> >>> oCommand.ExecuteNonQuery() >>> oCommand.Dispose() >>> oConn.Close() >>> 'MsgBox("Updated") >>> >>> End Sub >>>>>>Each checkbox looks like this:
>>><asp:CheckBox ID="Basecase_CheckBox" runat="server" Enabled="true" Text="Basecase" OnCheckedChanged="SaveCheckBoxes" /> >>>>>>This all works fine if all of the checkboxes are enabled. However, if a couple of them are disabled, as soon as I edit one of the remaining ones the status of the disabled ones goes to UnChecked and the table is updated to unchecked. I can't figure this out because there is NO binding and No call to the disabled checkboxes or their fields. I suspect it has something to do with viewstate but can't figure it out.