Question

how do I get checkboxlist to pass selected value on postback?

Asked by: bschave2

I have a for where a user fills it out and then can come back in and edit the form. When I save the form initially the checkbox list selected value comes through fine, but when i run it through edit mode and press submit, I lose the values in all of the checkbox lists. I do seem to be keeping the text box values, etc. Any help would be greatly appreciated!

Imports System
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports MySql.Data.MySqlClient
Imports System.Data
Imports System.Security.Principal
Partial Class _Default
    Inherits System.Web.UI.Page
    Dim conn As MySqlConnection
    Dim cmd As MySqlCommand
    Dim dr As MySqlDataReader
    Dim User1 As String
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim enq, thisYear, sigDate As String
        Dim mydate As Date
        Dim newyear As Integer
 
        'getting user identity through window authentication.
        User1 = Context.User.Identity.Name
 
        'taking off "etc/" if any.
        User1 = User1.Substring(4)
        Session("NTLOGON") = User1.ToUpper()
 
        'creates current year in title of page.
        mydate = Date.Today
        thisYear = mydate.Year.ToString()
        lblDate.Text = mydate.Year.ToString()
        newyear = lblDate.Text + 1
        lblDate.Text = newyear.ToString()
 
        If Page.IsPostBack = True Then
            Dim chkd, chkv, chkmb, chkms, medtrue As String
            'Request.Form.GetKey(x)
            chkd = chkdental.Items(0).Value.ToString()
            chkv = chkvision.Items(0).Value.ToString()
            chkmb = chkmedicalbase.Items(0).Value.ToString()
            medtrue = chkmedicalup.Items(0).Selected
            medtrue = chkmedicalup.Items(1).Selected
            medtrue = chkmedicalup.Items(2).Selected
            chkms = chkmedicalup.Items(0).Value.ToString()
            chkms = chkmedicalup.Items(0).Value.ToString()
        Else
 
            'checks to see if user has already filled out form for current year.
            Try
                conn = New MySqlConnection(ConfigurationManager.ConnectionStrings("appconnection").ToString())
                conn.Open()
 
                cmd = New MySqlCommand("SELECT count(*) FROM emp_benefit_info where user_id='" & User1 & "' and year_stamp='" & thisYear & "' and locked='locked'", conn)
                enq = cmd.ExecuteScalar()
 
                If enq = 0 Then
 
                    cmd = New MySqlCommand("SELECT count(*) FROM emp_benefit_info where user_id='" & User1 & "' and year_stamp='" & thisYear & "'", conn)
                    enq = cmd.ExecuteScalar()
 
                    'Response.Write(enq)
 
                    If enq = 0 Then
                        'loading items
                        getmedbase()
                        getmedplus()
                        getdental()
                        getvision()
                        dep1.Style.Add("display", "none")
                        plus.Style.Add("display", "none")
                        base.Style.Add("display", "none")
                        sigDate = Date.Today.Month.ToString() & "/" & Date.Today.Day.ToString() & "/" & Date.Today.Year.ToString()
                        txtsignaturedate.Text = sigDate.ToString
                        Session("insert") = "true"
                    Else
                        getmedbase()
                        getmedplus()
                        getdental()
                        getvision()
                        editBenefits()
                        plus.Style.Add("display", "none")
                        base.Style.Add("display", "none")
                        Session("insert") = "false"
                    End If
 
                    conn.Open()
 
                    cmd = New MySqlCommand("SELECT name, company FROM employees where userid='" & Session("NTLOGON") & "'", conn)
                    dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
 
                    While dr.Read()
                        txtname.Text = dr("name")
                        Session("company") = dr("company")
                    End While
 
                    dr.Close()
                    cmd.Connection.Close()
                    cmd.Connection.Dispose()
                    conn.Dispose()
 
 
                Else
                    Response.Redirect("locked.aspx")
 
                End If
 
 
            Catch ex As Exception
                lblStatus.Text = ex.Message
            End Try
 
        End If
 
    End Sub
 
    Protected Sub editBenefits()
        Dim thisdate As Date
        Dim benefitYear, itemcount As Integer
        Dim itemContains, enq As String
 
        Try
            thisdate = Date.Today
            benefitYear = thisdate.Year.ToString()
        Catch ex As Exception
            lblStatus.Text = ex.Message
        End Try
 
        conn = New MySqlConnection(ConfigurationManager.ConnectionStrings("appconnection").ToString())
        conn.Open()
 
        cmd = New MySqlCommand("SELECT company, name, cov_decline, emp_sup_life_elect, emp_sup_decline, year_stamp, dependents, medical_cov_price, dental_cov_price" & _
                               ",vision_cov_price, emp_dep_life_recip1, cast(date_format(emp_dep_bday, '%m/%d/%Y') as char) as emp_dep_bday" & _
                               ", cast(date_format(emp_yng_child_bday, '%m/%d/%Y') as char) as emp_yng_child_bday, marital_status, medical_cov_name, dental_cov_name" & _
                               ", vision_cov_name, emp_dep_life_recip2, emp_flex_med_elect, emp_flex_daycare_elect, emp_signature" & _
                               ", cast(date_format(emp_sig_date, '%m/%d/%Y') as char) as emp_sig_date, emp_flex_decline FROM emp_benefit_info" & _
                               " where user_id='" & Session("NTLOGON") & "' and year_stamp='" & benefitYear & "'", conn)
        dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
 
        While dr.Read()
            txtname.Text = dr("name")
 
            itemcount = radmarital.Items.Count
 
            If IsPostBack Then
 
            Else
 
                For i = 0 To itemcount - 1
                    If dr("marital_status").ToString = radmarital.Items(i).Text Then
                        radmarital.Items(i).Selected = True
                    End If
                Next
 
            End If
 
 
            itemcount = chkmedicalbase.Items.Count
 
            For i = 0 To itemcount - 1
 
                itemContains = chkmedicalbase.Items(i).Text.ToString()
                If itemContains.Contains(dr("medical_cov_name").ToString()) And itemContains.Contains(dr("medical_cov_price").ToString()) Then
                    chkmedicalbase.Items(i).Selected = True
                Else
                    chkmedicalbase.Items(i).Selected = False
                End If
 
            Next
 
 
            itemcount = chkmedicalup.Items.Count
 
            For i = 0 To itemcount - 1
 
                itemContains = chkmedicalup.Items(i).Text.ToString()
                If itemContains.Contains(dr("medical_cov_name").ToString()) And itemContains.Contains(dr("medical_cov_price").ToString()) Then
                    chkmedicalup.Items(i).Selected = True
                End If
 
            Next
 
            itemcount = chkdental.Items.Count
 
            For i = 0 To itemcount - 1
 
                itemContains = chkdental.Items(i).Text.ToString()
                If itemContains.Contains(dr("dental_cov_name").ToString()) And itemContains.Contains(dr("dental_cov_price").ToString()) Then
                    chkdental.Items(i).Selected = True
                End If
 
            Next
 
 
            itemcount = chkdental.Items.Count
 
            For i = 0 To itemcount - 1
 
                itemContains = chkdental.Items(i).Text.ToString()
                If itemContains.Contains(dr("dental_cov_name").ToString()) And itemContains.Contains(dr("dental_cov_price").ToString()) Then
                    chkdental.Items(i).Selected = True
                End If
 
            Next
 
 
            itemcount = chkvision.Items.Count
 
            For i = 0 To itemcount - 1
 
                itemContains = chkvision.Items(i).Text.ToString()
                If itemContains.Contains(dr("vision_cov_name").ToString()) And itemContains.Contains(dr("vision_cov_price").ToString()) Then
                    chkvision.Items(i).Selected = True
                End If
 
            Next
 
            If dr("cov_decline").ToString() = "Yes" Then
                declinemed.Checked = True
            Else
                declinemed.Checked = False
            End If
 
            itemcount = chkdependents.Items.Count
 
            For i = 0 To itemcount - 1
                itemContains = chkdependents.Items(i).Value.ToString()
                If itemContains = dr("dependents").ToString() Then
                    chkdependents.Items(i).Selected = True
                    Session("select_dependents") = True
                Else
                    chkdependents.Items(i).Selected = False
                End If
 
            Next
 
 
            Dim insur1, insur2, insur3 As String
            insur1 = chkinsurdep.Items(0).Text.ToString()
            insur2 = chkinsurdep.Items(1).Text.ToString()
            insur3 = chkinsurdep.Items(2).Text.ToString()
 
            Try
                If insur1 = dr("emp_dep_life_recip1").ToString() Then
                    chkinsurdep.Items(0).Selected = True
                End If
 
                If insur2 = dr("emp_dep_life_recip2").ToString() Then
                    chkinsurdep.Items(1).Selected = True
                End If
 
                If insur1 <> dr("emp_dep_life_recip1").ToString() And insur2 <> dr("emp_dep_life_recip2").ToString() Then
                    chkinsurdep.Items(2).Selected = True
                End If
            Catch ex As Exception
                lblStatus.Text = ex.Message
            End Try
 
            txtsupbday.Text = dr("emp_yng_child_bday")
            txtsupchildbday.Text = dr("emp_dep_bday")
            txtflexelectmed.Text = dr("emp_flex_med_elect")
            txtflexelectdaycare.Text = dr("emp_flex_daycare_elect")
            txtsignature.Text = dr("emp_signature")
            txtsignaturedate.Text = dr("emp_sig_date")
 
            itemcount = chksupelect.Items.Count
 
            For i = 0 To itemcount - 1
                itemContains = chksupelect.Items(i).Value.ToString()
                If itemContains = dr("emp_sup_life_elect").ToString() Then
                    chksupelect.Items(i).Selected = True
                Else
                    chksupelect.Items(i).Selected = False
                End If
 
            Next
 
            If dr("emp_sup_decline").ToString() = "Yes" Then
                chksupdecline.Checked = True
            Else
                chksupdecline.Checked = False
            End If
 
            If dr("emp_flex_decline").ToString() = "Yes" Then
                chkflexdecline.Checked = True
            Else
                chkflexdecline.Checked = False
            End If
 
 
 
        End While
 
        dr.Close()
 
 
        conn.Open()
        cmd = New MySqlCommand("SELECT count(*) FROM dependents where user_id='" & Session("NTLOGON") & "' and year_stamp='" & benefitYear & "'", conn)
        enq = cmd.ExecuteScalar()
        conn.Close()
 
        'gets dependents from DB.
        If enq > 0 Then
            Dim i As Integer = 1
            conn.Open()
 
            cmd = New MySqlCommand("SELECT dep_fname, dep_relationship, cast(date_format(dep_dob, '%m/%d/%Y') as char) as dep_dob, dep_sex, dep_ss, stays_w_employee, full_time_student FROM dependents where user_id='" & Session("NTLOGON") & "' and year_stamp='" & benefitYear & "'", conn)
            dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
 
            While dr.Read()
 
                dep1.Style.Add("display", "block")
                Dim dname, drelate, ddob, dsex, dss, dstay_W_employee, dfulltime As String
                dname = "txtdepname" + i.ToString
                drelate = "txtrelation" + i.ToString
                ddob = "txtbirth" + i.ToString
                dsex = "drpsex" + i.ToString
                dss = "txtsocial" + i.ToString
                dstay_W_employee = "drpdwelling" + i.ToString
                dfulltime = "drpstudent" + i.ToString
 
                Dim d, f, g As DropDownList
                Dim a, b, c, e As TextBox
                a = FindControl(dname)
                b = FindControl(drelate)
                c = FindControl(ddob)
                d = FindControl(dsex)
                e = FindControl(dss)
                f = FindControl(dstay_W_employee)
                g = FindControl(dfulltime)
 
                a.Text = dr("dep_fname")
                b.Text = dr("dep_relationship")
                c.Text = dr("dep_dob")
                d.SelectedValue = dr("dep_sex")
                e.Text = dr("dep_ss")
                f.SelectedValue = dr("stays_w_employee")
                g.SelectedValue = dr("full_time_student")
 
                i = i + 1
            End While
            dep1.Style.Add("display", "block")
        Else
            dep1.Style.Add("display", "none")
        End If
 
        dr.Close()
        cmd.Connection.Close()
        cmd.Connection.Dispose()
        conn.Dispose()
    End Sub
 
    Sub ftime_Clicked(ByVal sender As Object, ByVal e As EventArgs)
 
        Dim d1, d2, d3, d4, d5, drelate1, drelate2, drelate3, drelate4, drelate5 As String
        Dim dbirth1, dbirth2, dbirth3, dbirth4, dbirth5, dsex1, dsex2, dsex3, dsex4, dsex5 As String
        Dim dsocial1, dsocial2, dsocial3, dsocial4, dsocial5, ddwelling1, ddwelling2, ddwelling3, ddwelling4, ddwelling5 As String
        Dim dstudent1, dstudent2, dstudent3, dstudent4, dstudent5 As String
 
 
        Try
            If chkdependents.SelectedValue <> "" Then
                Session("sel_dependents") = True
                d1 = txtdepname1.Text
                d2 = txtdepname2.Text
                d3 = txtdepname3.Text
                d4 = txtdepname4.Text
                d5 = txtdepname5.Text
 
                drelate1 = txtrelation1.Text
                drelate2 = txtrelation2.Text
                drelate3 = txtrelation3.Text
                drelate4 = txtrelation4.Text
                drelate5 = txtrelation5.Text
 
                dbirth1 = txtbirth1.Text
                dbirth2 = txtbirth2.Text
                dbirth3 = txtbirth3.Text
                dbirth4 = txtbirth4.Text
                dbirth5 = txtbirth5.Text
 
                dsex1 = drpsex1.Text
                dsex2 = drpsex2.Text
                dsex3 = drpsex3.Text
                dsex4 = drpsex4.Text
                dsex5 = drpsex5.Text
 
                dsocial1 = txtsocial1.Text
                dsocial2 = txtsocial2.Text
                dsocial3 = txtsocial3.Text
                dsocial4 = txtsocial4.Text
                dsocial5 = txtsocial5.Text
 
                ddwelling1 = drpdwelling1.Text
                ddwelling2 = drpdwelling2.Text
                ddwelling3 = drpdwelling3.Text
                ddwelling4 = drpdwelling4.Text
                ddwelling5 = drpdwelling5.Text
 
                dstudent1 = drpstudent1.Text
                dstudent2 = drpstudent2.Text
                dstudent3 = drpstudent3.Text
                dstudent4 = drpstudent4.Text
                dstudent5 = drpstudent5.Text
 
                dep1.Style.Add("display", "block")
 
                txtdepname1.Text = d1
                txtdepname2.Text = d2
                txtdepname3.Text = d3
                txtdepname4.Text = d4
                txtdepname5.Text = d5
 
                txtrelation1.Text = drelate1
                txtrelation2.Text = drelate2
                txtrelation3.Text = drelate3
                txtrelation4.Text = drelate4
                txtrelation5.Text = drelate5
 
                txtbirth1.Text = dbirth1
                txtbirth2.Text = dbirth2
                txtbirth3.Text = dbirth3
                txtbirth4.Text = dbirth4
                txtbirth5.Text = dbirth5
 
                drpsex1.SelectedValue = dsex1
                drpsex2.SelectedValue = dsex2
                drpsex3.SelectedValue = dsex3
                drpsex4.SelectedValue = dsex4
                drpsex5.SelectedValue = dsex5
 
                txtsocial1.Text = dsocial1
                txtsocial2.Text = dsocial2
                txtsocial3.Text = dsocial3
                txtsocial4.Text = dsocial4
                txtsocial5.Text = dsocial5
 
                drpdwelling1.SelectedValue = ddwelling1
                drpdwelling2.SelectedValue = ddwelling2
                drpdwelling3.SelectedValue = ddwelling3
                drpdwelling4.SelectedValue = ddwelling4
                drpdwelling5.SelectedValue = ddwelling5
 
                drpstudent1.SelectedValue = dstudent1
                drpstudent2.SelectedValue = dstudent2
                drpstudent3.SelectedValue = dstudent3
                drpstudent4.SelectedValue = dstudent4
                drpstudent5.SelectedValue = dstudent5
 
            Else
                Session("sel_dependents") = False
                dep1.Style.Add("display", "none")
 
                txtdepname1.Text = ""
                txtdepname2.Text = ""
                txtdepname3.Text = ""
                txtdepname4.Text = ""
                txtdepname5.Text = ""
 
                txtrelation1.Text = ""
                txtrelation2.Text = ""
                txtrelation3.Text = ""
                txtrelation4.Text = ""
                txtrelation5.Text = ""
 
                txtbirth1.Text = ""
                txtbirth2.Text = ""
                txtbirth3.Text = ""
                txtbirth4.Text = ""
                txtbirth5.Text = ""
 
                drpsex1.SelectedValue = ""
                drpsex2.SelectedValue = ""
                drpsex3.SelectedValue = ""
                drpsex4.SelectedValue = ""
                drpsex5.SelectedValue = ""
 
                txtsocial1.Text = ""
                txtsocial2.Text = ""
                txtsocial3.Text = ""
                txtsocial4.Text = ""
                txtsocial5.Text = ""
 
                drpdwelling1.SelectedValue = ""
                drpdwelling2.SelectedValue = ""
                drpdwelling3.SelectedValue = ""
                drpdwelling4.SelectedValue = ""
                drpdwelling5.SelectedValue = ""
 
                drpstudent1.SelectedValue = ""
                drpstudent2.SelectedValue = ""
                drpstudent3.SelectedValue = ""
                drpstudent4.SelectedValue = ""
                drpstudent5.SelectedValue = ""
            End If
 
        Catch ex As Exception
            lblStatus.Text = ex.Message
        End Try
 
    End Sub
 
    Protected Sub getmedbase()
 
        conn = New MySqlConnection(ConfigurationManager.ConnectionStrings("appconnection").ToString())
        conn.Open()
 
        Try
            cmd = New MySqlCommand("SELECT * FROM coverage_types where type='medical base' order by list_order asc", conn)
            chkmedicalbase.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection)
            chkmedicalbase.ID = "chkbaseorder"
            chkmedicalbase.DataTextField = "description"
            chkmedicalbase.DataValueField = "description"
 
            chkmedicalbase.DataBind()
        Catch ex As Exception
            lblStatus.Text = ex.Message
        End Try
        conn.Dispose()
    End Sub
 
    Protected Sub getmedplus()
 
        conn = New MySqlConnection(ConfigurationManager.ConnectionStrings("appconnection").ToString())
        conn.Open()
 
        Try
            cmd = New MySqlCommand("SELECT * FROM coverage_types where type='medical up' order by list_order asc", conn)
            chkmedicalup.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection)
            chkmedicalup.ID = "chkuporder"
            chkmedicalup.DataTextField = "description"
            chkmedicalup.DataValueField = "description"
 
            chkmedicalup.DataBind()
        Catch ex As Exception
            lblStatus.Text = ex.Message
        End Try
 
        conn.Dispose()
    End Sub
 
    Protected Sub getdental()
 
        conn = New MySqlConnection(ConfigurationManager.ConnectionStrings("appconnection").ToString())
        conn.Open()
 
        Try
            cmd = New MySqlCommand("SELECT * FROM coverage_types where type='dental' order by list_order asc", conn)
            chkdental.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection)
            chkdental.ID = "chkdentalorder"
            chkdental.DataTextField = "description"
            chkdental.DataValueField = "description"
 
            chkdental.DataBind()
        Catch ex As Exception
            lblStatus.Text = ex.Message
        End Try
 
        conn.Dispose()
    End Sub
 
    Protected Sub getvision()
 
        conn = New MySqlConnection(ConfigurationManager.ConnectionStrings("appconnection").ToString())
        conn.Open()
 
        Try
            cmd = New MySqlCommand("SELECT * FROM coverage_types where type='vision' order by list_order asc", conn)
            chkvision.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection)
            chkvision.ID = "chkvisionorder"
            chkvision.DataTextField = "description"
            chkvision.DataValueField = "description"
 
            chkvision.DataBind()
        Catch ex As Exception
            lblStatus.Text = ex.Message
        End Try
 
        conn.Dispose()
    End Sub
 
 
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
 
        If Session("insert") = "true" Then
            insertdb()
        ElseIf Session("insert") = "false" Then
            upatedb()
        End If
 
    End Sub
 
    Sub insertdb()
        Dim name, medbase, medplus, dental, vision, medical_cov, med_decline, enq As String
        Dim maritalstatus, logon, company, medicaldeps, life_dep_type1, life_dep_type2, life_dep_bday, life_yng_child_bday, _
        life_sup_elect, life_sup_decline, flexelectmed, flexelectdaycare, signature, signaturedate, checkflexdecline, _
        medbase_price, medplus_price, med_price, dental_price, vision_price As String
        Dim year As Integer
        Dim i, itemcount As Integer
        Dim checkmeddeps As Boolean
        Dim moneyindex, moneylength, textindex As Integer
        Dim left, right As String
 
        'setting values equal to nothing so that items get verified correctly
        medbase = ""
        medplus = ""
        dental = ""
        vision = ""
        medicaldeps = ""
        life_dep_type1 = ""
        life_dep_type2 = ""
 
        'getting values for all form elelments to insert.
        itemcount = chkmedicalbase.Items.Count
 
        For i = 0 To itemcount - 1
            If chkmedicalbase.Items(i).Selected = "True" Then
                medbase = chkmedicalbase.Items(i).Value.ToString()
                moneylength = medbase.Length
                textindex = medbase.IndexOf(" biweekly*")
                moneyindex = medbase.IndexOf(" $")
                left = medbase.Substring(0, moneyindex)
                right = medbase.Substring(moneyindex + 2, textindex - moneyindex - 2)
                medbase = left
                medbase_price = right
            End If
        Next
 
 
        itemcount = chkmedicalup.Items.Count
 
        For i = 0 To itemcount - 1
            If chkmedicalup.Items(i).Selected = "True" Then
                medplus = chkmedicalup.Items(i).Value.ToString()
                moneylength = medplus.Length
                textindex = medplus.IndexOf(" biweekly*")
                moneyindex = medplus.IndexOf(" $")
                left = medplus.Substring(0, moneyindex)
                right = medplus.Substring(moneyindex + 2, textindex - moneyindex - 2)
                medplus = left
                medplus_price = right
                'Employee Only Coverage $43.38 biweekly*
            End If
        Next
 
        If medbase <> "" And medplus <> "" Then
            medical_cov = ""
        ElseIf medbase <> "" And medplus = "" Then
            medical_cov = medbase
            med_price = medbase_price
        ElseIf medplus <> "" And medbase = "" Then
            medical_cov = medplus
            med_price = medplus_price
        End If
 
 
        itemcount = chkdental.Items.Count
 
        For i = 0 To itemcount - 1
            If chkdental.Items(i).Selected = "True" Then
                dental = chkdental.Items(i).Value.ToString()
                moneylength = dental.Length
                textindex = dental.IndexOf(" biweekly*")
                moneyindex = dental.IndexOf(" $")
                left = dental.Substring(0, moneyindex)
                right = dental.Substring(moneyindex + 2, textindex - moneyindex - 2)
                dental = left
                dental_price = right
            End If
        Next
 
 
        itemcount = chkvision.Items.Count
 
        For i = 0 To itemcount - 1
            If chkvision.Items(i).Selected = "True" Then
                vision = chkvision.Items(i).Value.ToString()
                moneylength = vision.Length
                textindex = vision.IndexOf(" biweekly*")
                moneyindex = vision.IndexOf(" $")
                left = vision.Substring(0, moneyindex)
                right = vision.Substring(moneyindex + 2, textindex - moneyindex - 2)
                vision = left
                vision_price = right
            End If
        Next
 
 
        itemcount = chkdependents.Items.Count
 
        For i = 0 To itemcount - 1
            If chkdependents.Items(i).Selected = "True" Then
                medicaldeps = chkdependents.Items(i).Value.ToString()
            End If
        Next
 
        'checking to see if their are dependents entered in the form.
        If medicaldeps <> "" Then
            checkmeddeps = True
        End If
 
 
        itemcount = chkinsurdep.Items.Count
 
        For i = 0 To itemcount - 1
            If chkinsurdep.Items(i).Selected = "True" Then
                If chkinsurdep.Items(i).Value.ToString() = "Spouse" Then
                    life_dep_type1 = chkinsurdep.Items(i).Value.ToString()
                ElseIf chkinsurdep.Items(i).Value.ToString() = "Children" Then
                    life_dep_type2 = chkinsurdep.Items(i).Value.ToString()
                Else
                    life_dep_type1 = "None"
                    life_dep_type2 = "None"
                End If
 
            End If
        Next
 
 
        year = Date.Today.Year
        logon = Session("NTLOGON").ToString()
        company = Session("company").ToString()
        name = txtname.Text
        maritalstatus = radmarital.SelectedValue.ToString()
 
        Try
            med_decline = declinemed.Checked.ToString
        Catch ex As Exception
            med_decline = ""
        End Try
 
        If txtsupbday.Text = "" Then
            life_dep_bday = ""
        Else
            life_dep_bday = GetDateValue(txtsupbday.Text)
        End If
 
        If txtsupchildbday.Text = "" Then
            life_yng_child_bday = ""
        Else
            life_yng_child_bday = GetDateValue(txtsupchildbday.Text)
        End If
 
        Try
            life_sup_elect = chksupelect.SelectedItem.Value.ToString
        Catch ex As Exception
            life_sup_elect = ""
        End Try
 
        Try
            life_sup_decline = chksupdecline.Checked.ToString
        Catch ex As Exception
            life_sup_decline = ""
        End Try
 
        flexelectmed = txtflexelectmed.Text
        flexelectdaycare = txtflexelectdaycare.Text
        signature = txtsignature.Text
 
        If txtsignaturedate.Text = "" Then
            signaturedate = ""
        Else
            signaturedate = GetDateValue(txtsignaturedate.Text)
        End If
 
        Try
            checkflexdecline = chkflexdecline.Checked.ToString()
        Catch ex As Exception
            checkflexdecline = ""
        End Try
 
        If checkflexdecline = "True" Then
            checkflexdecline = "Yes"
        Else
            checkflexdecline = "No"
        End If
 
 
        'converting values for drp downs b4 going into DB.
        If med_decline = "True" Then
            med_decline = "Yes"
        Else
            med_decline = "No"
        End If
 
 
        If life_sup_decline = "True" Then
            life_sup_decline = "Yes"
        Else
            life_sup_decline = "No"
        End If
 
 
        If checkflexdecline = "True" Then
            life_sup_decline = "Yes"
        Else
            checkflexdecline = "No"
        End If
 
        'checking if user signed up for more than one medical plan.
        If medical_cov = "" Then
            lblError.Text = "You cannot choose more than one medical coverage plan. Please select ONLY one medical coverage plan."
            plus.Style.Add("display", "block")
            base.Style.Add("display", "block")
        Else
            plus.Style.Add("display", "none")
            base.Style.Add("display", "none")
            lblError.Text = ""
 
            Try
                conn = New MySqlConnection(ConfigurationManager.ConnectionStrings("appconnection").ToString())
                conn.Open()
                cmd = New MySqlCommand _
                ("INSERT INTO emp_benefit_info(user_id,company,name,cov_decline,marital_status,emp_sup_life_elect" & _
                ",emp_sup_decline,year_stamp,dependents,medical_cov_price,dental_cov_price,vision_cov_price" & _
                ",medical_cov_name,dental_cov_name,vision_cov_name,emp_dep_life_recip1,emp_dep_life_recip2" & _
                ",emp_dep_bday,emp_yng_child_bday,emp_flex_med_elect,emp_flex_daycare_elect" & _
                ",emp_flex_decline,emp_signature, emp_sig_date) values('" & logon & "','" & company & "','" & name & "'" & _
                ",'" & med_decline & "','" & maritalstatus & "','" & life_sup_elect & "','" & life_sup_decline & "'" & _
                ",'" & year & "','" & medicaldeps & "','" & med_price & "','" & dental_price & "'" & _
                ",'" & vision_price & "','" & medical_cov & "','" & dental & "','" & vision & "','" & life_dep_type1 & "'" & _
                ",'" & life_dep_type2 & "','" & life_dep_bday & "','" & life_yng_child_bday & "'" & _
                ",'" & flexelectmed & "','" & flexelectdaycare & "','" & checkflexdecline & "','" & signature & "'" & _
                ",'" & signaturedate & "')", conn)
                enq = cmd.ExecuteNonQuery()
 
                cmd.Connection.Close()
                cmd.Connection.Dispose()
 
                'checking to see if dependents were added.
                If checkmeddeps = True Then
                    Dim x As Integer = 1
                    Dim depname, deprelate, depbirth, depsex, depsocial, depdwelling, depstudent As String
 
                    'looping through each table row to get all data that was entered.
                    Do Until x = 5
                        depname = Request.Form("txtdepname" & x)
                        deprelate = Request.Form("txtrelation" & x)
                        depbirth = GetDateValue(Request.Form("txtbirth" & x))
                        depsex = Request.Form("drpsex" & x)
                        depsocial = Request.Form("txtsocial" & x)
                        depdwelling = Request.Form("drpdwelling" & x)
                        depstudent = Request.Form("drpstudent" & x)
 
                        If depname <> "" Then
 
                            conn = New MySqlConnection(ConfigurationManager.ConnectionStrings("appconnection").ToString())
                            conn.Open()
                            cmd = New MySqlCommand("INSERT INTO dependents(user_id,company,year_stamp,dep_fname,dep_relationship,dep_dob," & _
                                                   "dep_sex,dep_ss,stays_w_employee,full_time_student) " & _
                                                   "values('" & logon & "','" & company & "','" & year & "','" & depname & "','" & deprelate & "'" & _
                                                   ",'" & depbirth & "','" & depsex & "','" & depsocial & "'" & _
                                                   ",'" & depdwelling & "','" & depstudent & "')", conn)
                            enq = cmd.ExecuteNonQuery()
 
                            cmd.Connection.Close()
                            cmd.Connection.Dispose()
 
                            conn.Close()
                            conn.Dispose()
 
                        End If
 
                        x = x + 1
                    Loop
 
                End If
 
            Catch ex As Exception
                lblStatus.Text = ex.Message
            End Try
        End If
    End Sub
 
 
    Sub upatedb()
        Dim name, medbase, medplus, dental, vision, medical_cov, med_decline, enq As String
        Dim maritalstatus, logon, company, medicaldeps, life_dep_type, life_dep_bday, life_yng_child_bday, _
        life_sup_elect, life_sup_decline, flexelectmed, flexelectdaycare, signature, signaturedate, checkflexdecline As String
        Dim year As Integer
        Dim i, itemcount As Integer
        Dim checkmeddeps As Boolean
 
        'setting values equal to nothing so that items get verified correctly
        medbase = ""
        medplus = ""
        dental = ""
        vision = ""
        medicaldeps = ""
        life_dep_type = ""
 
        'getting values for all form elelments to insert.
        itemcount = chkmedicalbase.Items.Count
 
        For i = 0 To itemcount - 1
            If chkmedicalbase.Items(i).Selected = True Then
                medbase = chkmedicalbase.Items(i).Value.ToString()
            End If
        Next
 
 
        itemcount = chkmedicalup.Items.Count
 
        For i = 0 To itemcount - 1
            If chkmedicalup.Items(i).Selected = True Then
                medplus = chkmedicalup.Items(i).Value.ToString()
            End If
        Next
 
        If medbase <> "" And medplus <> "" Then
            medical_cov = ""
        ElseIf medbase <> "" And medplus = "" Then
            medical_cov = medbase
        ElseIf medplus <> "" And medbase = "" Then
            medical_cov = medplus
        End If
 
 
        itemcount = chkdental.Items.Count
 
        For i = 0 To itemcount - 1
            If chkdental.Items(i).Selected = True Then
                dental = chkdental.Items(i).Value.ToString()
            End If
        Next
 
 
        itemcount = chkvision.Items.Count
 
        For i = 0 To itemcount - 1
            If chkvision.Items(i).Selected = True Then
                vision = chkvision.Items(i).Value.ToString()
            End If
        Next
 
 
        itemcount = chkdependents.Items.Count
 
        For i = 0 To itemcount - 1
            If chkdependents.Items(i).Selected = True Then
                medicaldeps = chkdependents.Items(i).Value.ToString()
            End If
        Next
 
        'checking to see if their are dependents entered in the form.
        If medicaldeps <> "" Then
            checkmeddeps = True
        End If
 
 
        itemcount = chkinsurdep.Items.Count
 
        For i = 0 To itemcount - 1
            If chkinsurdep.Items(i).Selected = True Then
                life_dep_type = chkinsurdep.Items(i).Value.ToString()
            End If
        Next
 
 
        year = Date.Today.Year
        logon = Session("NTLOGON").ToString()
        company = Session("company").ToString()
        name = txtname.Text
 
        Try
            maritalstatus = radmarital.SelectedValue.ToString()
        Catch ex As Exception
            maritalstatus = ""
        End Try
 
        med_decline = declinemed.Checked.ToString
        life_dep_bday = txtsupbday.Text
        life_yng_child_bday = txtsupchildbday.Text
 
        Try
            life_sup_elect = chksupelect.SelectedItem.Value.ToString
        Catch ex As Exception
            life_sup_elect = ""
        End Try
 
        life_sup_decline = chksupdecline.Checked.ToString
        flexelectmed = txtflexelectmed.Text
        flexelectdaycare = txtflexelectdaycare.Text
        signature = txtsignature.Text
        signaturedate = GetDateValue(txtsignaturedate.Text)
        checkflexdecline = chkflexdecline.Checked.ToString()
 
 
        'converting values for drp downs b4 going into DB.
        If med_decline = True Then
            med_decline = "Yes"
        Else
            med_decline = ""
        End If
 
 
        If life_sup_decline = True Then
            life_sup_decline = "Yes"
        Else
            life_sup_decline = ""
        End If
 
 
        If checkflexdecline = True Then
            life_sup_decline = "Yes"
        Else
            checkflexdecline = ""
        End If
 
        'checking if user signed up for more than one medical plan.
        If medical_cov = "" Then
            lblError.Text = "You cannot choose more than one medical coverage plan. Please select ONLY one medical coverage plan."
            plus.Style.Add("display", "block")
            base.Style.Add("display", "block")
        Else
            plus.Style.Add("display", "none")
            base.Style.Add("display", "none")
            lblError.Text = ""
 
            Try
                'conn = New MySqlConnection(ConfigurationManager.ConnectionStrings("appconnection").ToString())
                'conn.Open()
                'cmd = New MySqlCommand("INSERT INTO emp_benefit_info(user_id,company,name,cov_decline,marital_status,emp_sup_life_elect," & _
                '                       "emp_sup_decline,year_stamp,dependents,medical_cov,dental_cov,vision_cov,emp_dep_life_recip," & _
                '                       "emp_life_bday,emp_yng_child_bday,emp_flex_med_elect,emp_flex_daycare_elect,emp_signature, emp_date)" & _
                '                        " values('" & logon & "','" & company & "','" & name & "'" & _
                '                       "'" & med_decline & "','" & maritalstatus & "','" & life_sup_elect & "','" & life_sup_decline & "'," & _
                '                       "'" & year & "','" & medicaldeps & "','" & medical_cov & "','" & dental & "','" & vision & "'," & _
                '                       "'" & life_dep_type & "','" & life_dep_bday & "','" & life_yng_child_bday & "')", conn)
                'enq = cmd.ExecuteNonQuery()
 
                'cmd.Connection.Close()
                'cmd.Connection.Dispose()
 
                'checking to see if dependents were added.
                If checkmeddeps = True Then
                    Dim x As Integer
                    Dim depname, deprelate, depbirth, depsex, depsocial, depdwelling, depstudent As String
 
                    x = 1
 
                    'looping through each table row to get all data that was entered.
                    Do Until x = 5
                        depname = Request.Form("txtdepname" & x)
                        deprelate = Request.Form("txtrelation" & x)
                        depbirth = Request.Form("txtbirth" & x)
                        depsex = Request.Form("drpsex" & x)
                        depsocial = Request.Form("txtsocial" & x)
                        depdwelling = Request.Form("drpdwelling" & x)
                        depstudent = Request.Form("drpstudent" & x)
 
                        If depname <> "" Then
 
                            'conn = New MySqlConnection(ConfigurationManager.ConnectionStrings("appconnection").ToString())
                            'conn.Open()
                            'cmd = New MySqlCommand("INSERT INTO dependents(user_id,company,year_stamp,depfname,dep_relationship,dep_dob," & _
                            '                       "dep_sex,dep_ss,stays_w_employee,full_time_student) " & _
                            '                       "values('" & logon & "','" & company & "','" & name & "''" & med_decline & "'," & _
                            '                       "'" & med_decline & "','" & maritalstatus & "','" & life_sup_elect & "','" & life_sup_decline & "'," & _
                            '                       "'" & year & "','" & medicaldeps & "')", conn)
                            'enq = cmd.ExecuteNonQuery()
 
                            'cmd.Connection.Close()
                            'cmd.Connection.Dispose()
 
                            'conn.Close()
                            'conn.Dispose()
 
                        End If
 
                        x = x + 1
                    Loop
 
                End If
 
            Catch ex As Exception
                lblStatus.Text = ex.Message
            End Try
        End If
    End Sub
 
    Public Shared Function GetDateValue(ByVal sVal As String) As String
        Dim yr, mo, day As String
        Dim replaceMonth, replaceDay As String
        Try
            If sVal.Length = 8 Then
                yr = sVal.Substring(4, 4)
                replaceMonth = sVal.Substring(0, 2)
                mo = replaceMonth.IndexOf("/")
 
                If mo <= "0" Then
                    mo = sVal.Substring(0, 2)
                Else
                    mo = "0" & sVal.Substring(0, 1)
                End If
 
                replaceDay = sVal.Substring(3, 2)
                day = replaceDay.IndexOf("/")
 
                If day = "1" Then
                    day = sVal.Substring(2, 2)
                Else
                    day = "0" & sVal.Substring(2, 1)
                End If
 
                sVal = yr & "-" & mo & "-" & day
 
            ElseIf sVal.Length = 9 Then
                yr = sVal.Substring(5, 4)
 
                replaceMonth = sVal.Substring(0, 2)
                mo = replaceMonth.IndexOf("/")
 
                If mo <= "0" Then
                    mo = sVal.Substring(0, 2)
                Else
                    mo = "0" & sVal.Substring(0, 1)
                End If
 
                If mo > 9 Then
 
                    replaceDay = sVal.Substring(3, 1)
                    day = replaceDay.IndexOf("/")
 
                    If day = "1" Then
                        day = sVal.Substring(2, 2)
                    Else
                        day = "0" & sVal.Substring(3, 1)
                    End If
 
                    sVal = yr & "-" & mo & "-" & day
 
                Else
 
                    replaceDay = sVal.Substring(3, 2)
                    day = replaceDay.IndexOf("/")
 
                    If day = "1" Then
                        day = sVal.Substring(2, 2)
                    Else
                        day = "0" & sVal.Substring(2, 1)
                    End If
 
                    sVal = yr & "-" & mo & "-" & day
 
                End If
 
            ElseIf sVal.Length = 10 Then
                yr = sVal.Substring(6, 4)
 
                replaceMonth = sVal.Substring(0, 2)
                mo = replaceMonth.IndexOf("/")
 
                If mo <= "0" Then
                    mo = sVal.Substring(0, 2)
                Else
                    mo = "0" & sVal.Substring(0, 1)
                End If
 
                replaceDay = sVal.Substring(3, 2)
                day = replaceDay.IndexOf("/")
 
                If day <= "0" Then
                    day = sVal.Substring(3, 2)
                Else
                    day = sVal.Substring(2, 2)
                End If
 
                sVal = yr & "-" & mo & "-" & day
            Else
                sVal = "0000-00-00"
            End If
 
        Catch generatedExceptionName As Exception
 
        End Try
 
        Return sVal
    End Function
End Class

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
400:
401:
402:
403:
404:
405:
406:
407:
408:
409:
410:
411:
412:
413:
414:
415:
416:
417:
418:
419:
420:
421:
422:
423:
424:
425:
426:
427:
428:
429:
430:
431:
432:
433:
434:
435:
436:
437:
438:
439:
440:
441:
442:
443:
444:
445:
446:
447:
448:
449:
450:
451:
452:
453:
454:
455:
456:
457:
458:
459:
460:
461:
462:
463:
464:
465:
466:
467:
468:
469:
470:
471:
472:
473:
474:
475:
476:
477:
478:
479:
480:
481:
482:
483:
484:
485:
486:
487:
488:
489:
490:
491:
492:
493:
494:
495:
496:
497:
498:
499:
500:
501:
502:
503:
504:
505:
506:
507:
508:
509:
510:
511:
512:
513:
514:
515:
516:
517:
518:
519:
520:
521:
522:
523:
524:
525:
526:
527:
528:
529:
530:
531:
532:
533:
534:
535:
536:
537:
538:
539:
540:
541:
542:
543:
544:
545:
546:
547:
548:
549:
550:
551:
552:
553:
554:
555:
556:
557:
558:
559:
560:
561:
562:
563:
564:
565:
566:
567:
568:
569:
570:
571:
572:
573:
574:
575:
576:
577:
578:
579:
580:
581:
582:
583:
584:
585:
586:
587:
588:
589:
590:
591:
592:
593:
594:
595:
596:
597:
598:
599:
600:
601:
602:
603:
604:
605:
606:
607:
608:
609:
610:
611:
612:
613:
614:
615:
616:
617:
618:
619:
620:
621:
622:
623:
624:
625:
626:
627:
628:
629:
630:
631:
632:
633:
634:
635:
636:
637:
638:
639:
640:
641:
642:
643:
644:
645:
646:
647:
648:
649:
650:
651:
652:
653:
654:
655:
656:
657:
658:
659:
660:
661:
662:
663:
664:
665:
666:
667:
668:
669:
670:
671:
672:
673:
674:
675:
676:
677:
678:
679:
680:
681:
682:
683:
684:
685:
686:
687:
688:
689:
690:
691:
692:
693:
694:
695:
696:
697:
698:
699:
700:
701:
702:
703:
704:
705:
706:
707:
708:
709:
710:
711:
712:
713:
714:
715:
716:
717:
718:
719:
720:
721:
722:
723:
724:
725:
726:
727:
728:
729:
730:
731:
732:
733:
734:
735:
736:
737:
738:
739:
740:
741:
742:
743:
744:
745:
746:
747:
748:
749:
750:
751:
752:
753:
754:
755:
756:
757:
758:
759:
760:
761:
762:
763:
764:
765:
766:
767:
768:
769:
770:
771:
772:
773:
774:
775:
776:
777:
778:
779:
780:
781:
782:
783:
784:
785:
786:
787:
788:
789:
790:
791:
792:
793:
794:
795:
796:
797:
798:
799:
800:
801:
802:
803:
804:
805:
806:
807:
808:
809:
810:
811:
812:
813:
814:
815:
816:
817:
818:
819:
820:
821:
822:
823:
824:
825:
826:
827:
828:
829:
830:
831:
832:
833:
834:
835:
836:
837:
838:
839:
840:
841:
842:
843:
844:
845:
846:
847:
848:
849:
850:
851:
852:
853:
854:
855:
856:
857:
858:
859:
860:
861:
862:
863:
864:
865:
866:
867:
868:
869:
870:
871:
872:
873:
874:
875:
876:
877:
878:
879:
880:
881:
882:
883:
884:
885:
886:
887:
888:
889:
890:
891:
892:
893:
894:
895:
896:
897:
898:
899:
900:
901:
902:
903:
904:
905:
906:
907:
908:
909:
910:
911:
912:
913:
914:
915:
916:
917:
918:
919:
920:
921:
922:
923:
924:
925:
926:
927:
928:
929:
930:
931:
932:
933:
934:
935:
936:
937:
938:
939:
940:
941:
942:
943:
944:
945:
946:
947:
948:
949:
950:
951:
952:
953:
954:
955:
956:
957:
958:
959:
960:
961:
962:
963:
964:
965:
966:
967:
968:
969:
970:
971:
972:
973:
974:
975:
976:
977:
978:
979:
980:
981:
982:
983:
984:
985:
986:
987:
988:
989:
990:
991:
992:
993:
994:
995:
996:
997:
998:
999:
1000:
1001:
1002:
1003:
1004:
1005:
1006:
1007:
1008:
1009:
1010:
1011:
1012:
1013:
1014:
1015:
1016:
1017:
1018:
1019:
1020:
1021:
1022:
1023:
1024:
1025:
1026:
1027:
1028:
1029:
1030:
1031:
1032:
1033:
1034:
1035:
1036:
1037:
1038:
1039:
1040:
1041:
1042:
1043:
1044:
1045:
1046:
1047:
1048:
1049:
1050:
1051:
1052:
1053:
1054:
1055:
1056:
1057:
1058:
1059:
1060:
1061:
1062:
1063:
1064:
1065:
1066:
1067:
1068:
1069:
1070:
1071:
1072:
1073:
1074:
1075:
1076:
1077:
1078:
1079:
1080:
1081:
1082:
1083:
1084:
1085:
1086:
1087:
1088:
1089:
1090:
1091:
1092:
1093:
1094:
1095:
1096:
1097:
1098:
1099:
1100:
1101:
1102:
1103:
1104:
1105:
1106:
1107:
1108:
1109:
1110:
1111:
1112:
1113:
1114:
1115:
1116:
1117:
1118:
1119:
1120:
1121:
1122:
1123:
1124:
1125:
1126:
1127:
1128:
1129:
1130:
1131:
1132:
1133:
1134:
1135:
1136:
1137:
1138:
1139:
1140:
1141:
1142:
1143:
1144:
1145:
1146:
1147:
1148:
1149:
1150:
1151:
1152:
1153:
1154:
1155:
1156:
1157:
1158:
1159:
1160:
1161:
1162:
1163:
1164:
1165:
1166:
1167:
1168:
1169:
1170:
1171:
1172:
1173:
1174:
1175:
1176:
1177:
1178:
1179:
1180:
1181:
1182:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-10-19 at 10:09:46ID24824272
Topic

Microsoft Visual Basic.Net

Participating Experts
2
Points
500
Comments
10

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Validating a CheckboxList in ASP.Net
    Hi! I have the following checkboxlist on my ASP.NET form: _______________________ <asp:CheckBoxList id="role" runat="server" ToolTip="Select all that apply." font-family="Arial" font-size="12px" RepeatDirection="V...
  2. CheckBoxList
    CheckBoxList Question: Hello experts I have a checkboxlist on my webform. I'm trying to sum up the values for each selection made by the user. My problem is that I have two types of data in the checkboxlist. My list looks like this: 200 Chrome Wheels +250 500 Sunroof...
  3. Checkboxlist validation using CustomValidator in ASP.NET …
    I have a checkbox list with 10 items. One of the item is "Other" . If user checks the "Other" item he has to fill description on a textbox. I want to put a validation on this if user checks "other" item in checkbox list, he has to enter somethi...
  4. checkboxlist validation problem
    hi there, seen loads of this on the net but it doesnt answer my question really, hence posting here. I have the following which needs to be checked before form submission <asp:CheckBoxList ID="CheckBoxList4" runat="server"&...
  5. CheckBoxList loses state
    Hi, I have an asp.net CheckBoxList, that loses it's items on post back, and therefore it's selected state. Any ideas would be greatly appreciated

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: sevensnake77Posted on 2009-10-19 at 13:48:28ID: 25608873

you want to have the checkbox change the value in the database when checked or unchecked correct?

 

by: bschave2Posted on 2009-10-19 at 13:57:06ID: 25608951

no. When i have saved my data, everything works fine, but when I come back into my for and populate all of my items into the form....a.k.a. edit mode, i have problems keeping those values when I edit some items and then hit submit.

 

by: bschave2Posted on 2009-10-19 at 13:57:44ID: 25608963

only for the radio lists and check box lists

 

by: sevensnake77Posted on 2009-10-19 at 14:27:44ID: 25609220

Ok there is way to much code to review can you just show us the code where the radio list and checkbox lists are bounded.

Or maybe if I am correct try to use a function Itemdatabound.

 

by: bschave2Posted on 2009-10-19 at 14:29:32ID: 25609233

these are the functions i have to populate the checkbox lists....


Protected Sub getmedplus()

        conn = New MySqlConnection(ConfigurationManager.ConnectionStrings("appconnection").ToString())
        conn.Open()

        Try
            cmd = New MySqlCommand("SELECT * FROM coverage_types where type='medical up' order by list_order asc", conn)
            chkmedicalup.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection)
            chkmedicalup.ID = "chkuporder"
            chkmedicalup.DataTextField = "description"
            chkmedicalup.DataValueField = "description"
            chkmedicalup.DataBind()
        Catch ex As Exception
            lblStatus.Text = ex.Message
        End Try

        conn.Dispose()
    End Sub

    Protected Sub getdental()

        conn = New MySqlConnection(ConfigurationManager.ConnectionStrings("appconnection").ToString())
        conn.Open()

        Try
            cmd = New MySqlCommand("SELECT * FROM coverage_types where type='dental' order by list_order asc", conn)
            chkdental.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection)
            chkdental.ID = "chkdentalorder"
            chkdental.DataTextField = "description"
            chkdental.DataValueField = "description"

            chkdental.DataBind()
        Catch ex As Exception
            lblStatus.Text = ex.Message
        End Try

        conn.Dispose()
    End Sub

    Protected Sub getvision()

        conn = New MySqlConnection(ConfigurationManager.ConnectionStrings("appconnection").ToString())
        conn.Open()

        Try
            cmd = New MySqlCommand("SELECT * FROM coverage_types where type='vision' order by list_order asc", conn)
            chkvision.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection)
            chkvision.ID = "chkvisionorder"
            chkvision.DataTextField = "description"
            chkvision.DataValueField = "description"

            chkvision.DataBind()
        Catch ex As Exception
            lblStatus.Text = ex.Message
        End Try

        conn.Dispose()
    End Sub

    Protected Sub onindexchange1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)

        Dim itemcount As Integer
        Dim medbase As String
        medbase = ""

        itemcount = chkmedicalbase.Items.Count

        For i = 0 To itemcount - 1
            If chkmedicalbase.Items(i).Selected = True Then
                medbase = chkmedicalbase.Items(i).Value.ToString()
            End If
        Next


        Session("medbase") = medbase

    End Sub

 

by: bschave2Posted on 2009-10-19 at 14:46:21ID: 25609333

i don't understand why the selected value keeps getting lost.

 

by: CodeCruiserPosted on 2009-10-20 at 03:44:34ID: 25612665

Do you have viewstate enabled for the checkedlistboxes?

 

by: bschave2Posted on 2009-10-20 at 11:57:17ID: 25617233

their was a number of issues wrong, so I will just give the sample code on the right way to dynamically pass checkboxlist data.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        conn = New MySqlConnection(ConfigurationManager.ConnectionStrings("appconnection").ToString())
        conn.Open()
        Dim i As Integer
        Dim listi, arrayva11, arrayval2 As String
        i = 0

        If Not IsPostBack Then
            Dim itemArray As New ArrayList()

            Try
                cmd = New MySqlCommand("SELECT medical_cov_name, medical_cov_price FROM emp_benefit_info where user_id='bschave' and year_stamp='2009'", conn)
                dr = cmd.ExecuteReader()

                While dr.Read()
                    itemArray.Add(dr("medical_cov_name"))
                    itemArray.Add(dr("medical_cov_price"))

                    i = i + 1
                End While
                dr.Close()

                i = 0

                cmd = New MySqlCommand("SELECT * FROM coverage_types where type='medical up' order by list_order asc", conn)
                dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)

                While dr.Read()

                    chkmedicalbase.Items.Add(New ListItem(dr("description")))

                    listi = chkmedicalbase.Items(i).Value.ToString()
                    arrayva11 = itemArray(0).ToString
                    arrayval2 = itemArray(1).ToString

                    If listi.Contains(arrayval2) Then
                        chkmedicalbase.Items(i).Selected = True
                    End If


                    i = i + 1
                End While
                dr.Close()

            Catch ex As Exception
                lblStatus.Text = ex.Message
            End Try
        End If
        conn.Dispose()
    End Sub

    Protected Sub getmedbase()

        conn = New MySqlConnection(ConfigurationManager.ConnectionStrings("appconnection").ToString())
        conn.Open()

        Try
            cmd = New MySqlCommand("SELECT * FROM coverage_types where type='medical base' order by list_order asc", conn)
            chkmedicalbase.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection)
            chkmedicalbase.ID = "chkmedicalbase"
            chkmedicalbase.DataTextField = "description"
            chkmedicalbase.DataValueField = "description"

            chkmedicalbase.DataBind()

            Dim itemcount As Integer
            Dim itemContains As String
            itemcount = chkmedicalbase.Items.Count

            For i = 0 To itemcount - 1

                itemContains = chkmedicalbase.Items(i).Text.ToString()
                If itemContains = Session("medbase") Then
                    chkmedicalbase.Items(i).Selected = True
                Else
                    chkmedicalbase.Items(i).Selected = False
                End If

            Next
        Catch ex As Exception
            lblStatus.Text = ex.Message
        End Try
        conn.Dispose()
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        getmedbase()
    End Sub

    Protected Sub change(ByVal sender As Object, ByVal e As EventArgs)

        Dim itemcount As Integer
        Dim medbase As String
        medbase = ""

        itemcount = chkmedicalbase.Items.Count

        For i = 0 To itemcount - 1
            If chkmedicalbase.Items(i).Selected = True Then
                Session("medplus") = chkmedicalbase.Items(i).Value.ToString()

            End If
        Next


        Session("medplus") = medbase

    End Sub

 

by: bschave2Posted on 2009-10-20 at 12:00:19ID: 25617258

upon editing a checkbox list selection you have to bind the data and loop through the selected item from the database. then you just have to keep up with the new selected items....edited items....in my case, I did it with a session.

thanks for the help though.

 

by: bschave2Posted on 2009-10-20 at 12:05:32ID: 31642996

splitting because both guys attempted to help. although you have to have the viewstate set to true and you have to have a databind funtction, there is more to it than that.

thanks for the help!

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...