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 7945581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:54:31+00:00 2026-06-04T00:54:31+00:00

I have a checkbox list which is filled with entries from my database on

  • 0

I have a checkbox list which is filled with entries from my database on page load. I need to update an entry in my database when a item is checked and when an item is unchecked. Right now I am doing the following:

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

</asp:CheckBoxList>

And the function:

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

But when I uncheck a button the else case is never ran. Also, if I have 4 buttons checked and I uncheck all four buttons, when I uncheck the fourth button I get an error at the line:

If check1.SelectedItem.Selected = True Then

The error is: “Object reference not set to an instance of an object.”

Is there a better way to check if a list item is checked or unchecked?

Thanks

  • 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-04T00:54:33+00:00Added an answer on June 4, 2026 at 12:54 am
    for (int i = 0; i < check1.Items.Count; i++)
      if (check1.GetItemChecked(i))
        // Do selected stuff
      else
        // Do unselected stuff
    

    If the the check is in indeterminate state, this will still return true. You may want to replace

    if (check1.GetItemChecked(i))
    

    with

    if (check1.GetItemCheckState(i) == CheckState.Checked)
    

    if you want to only include actually checked items.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a checkbox list of items. I need to update my database to
I have a problem with listview which list item contain a checkbox. When i
I have a list item which contains a CheckBox, and I want to be
We have an ASP.Net page that uses a checkbox to toggle between a list
I'm a tad confused. I have a Repeater which populates a list of Checkbox
I'd like to have X number of Ajax panels on my list page which
I have a form which contains list of data, I added a checkbox in
Hi All I need a CheckBox Dropdown list control in asp.net i have seen
I have the following sample code which gets a list of values from a
I have contact list which contains (checkbox,firstname,lastname,phone). I am creating this list using html

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.