Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7952163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:46:43+00:00 2026-06-04T02:46:43+00:00

I have a form which contains a checkbox field. On page load I want

  • 0

I have a form which contains a checkbox field. On page load I want to create a separate checkbox for each customer in my Database. The code I have to create the checkboxes for each customer works fine. However, I also want to check in the database if the customer is set to unauthorized if they are then I want to check there box. I also have code for the case where the user checks a box. If a box is checked I update the database setting the unauthorized attribute to true. My problem is when I check a box it works fine and the box is checked, however if I reload the page all the boxes are unchecked. So either my database update is not updating the database or the way I check on page load for checked boxes is incorrect. Any ideas?

The code for the asp checkbox field:

<asp:CheckBoxList id="check1" AutoPostBack="True" TextAlign="Right" OnSelectedIndexChanged="Check" runat="server">

</asp:CheckBoxList>

The Code for the page load:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim sql As String = "SELECT Name, unauthorized, ID FROM Customer ORDER BY Name"
    Dim dt As DataTable = db.execDataTableQuery(sql, "Customer")
            Dim i As Integer
            For i = 0 To dt.Rows.Count - 1
                check1.Items.Add(New ListItem(CStr(dt.Rows(i).Item("Name"))))
                check1.Items(i).Value = CInt(dt.Rows(i).Item("ID"))
                check1.Items(i).Text = CStr(dt.Rows(i).Item("Name"))
                If CInt(dt.Rows(i).Item("unauthorized")) = 1 Then
                    check1.Items(i).Selected = 1
                Else
                    check1.Items(i).Selected = 0
                End If
            Next

        End Sub

The code to update the database:

    Sub Check(ByVal sender As Object, ByVal e As EventArgs)
        Dim sql As String
        If check1.SelectedItem.Selected = 1 Then
            sql = "UPDATE Customer SET unauthorized = 1 WHERE ID = @ID"
            db.execUpdateQuery(sql, New SqlClient.SqlParameter("@ID", check1.SelectedItem.Value))
        Else
            sql = "UPDATE Customer SET unauthorized = 0 WHERE ID = @ID"
            db.execUpdateQuery(sql, New SqlClient.SqlParameter("@ID", check1.SelectedItem.Value))
        End If
    End Sub

End Class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T02:46:45+00:00Added an answer on June 4, 2026 at 2:46 am

    You need to wrap you code in Page_Load in a Not Page.IsPostback, otherwise on postback no events are triggered and the selection is lost since you’re overwriting it from database.

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostback Then
            ' databind your CheckBoxList '
        End If
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form which contains some rows, each has a checkbox in the
I have a WPF form which contains 30x30 grid where each grid cell is
I have a form which contains list of data, I added a checkbox in
I have a aspx page which contains the following CheckBoxList. <form id=form1 runat=server> <asp:CheckBoxList
I have this page (code below) which contains a series of 5 checkboxes, all
I have a form which contains several standard controls (textbox's, buttons, etc). I want
So I have a hidden field on my form which contains a URL (EG
I have a form which contains a dropdown list of countries generated from database.
I have a form which contains a lot of elements, my DB guy has
i have a registration form which contains a postalcode and a country drop down

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.