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

  • SEARCH
  • Home
  • 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 8274519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:45:07+00:00 2026-06-08T07:45:07+00:00

(C# ASP Site) Right now I have a CheckBoxList that is prechecked, depending on

  • 0

(C# ASP Site) Right now I have a CheckBoxList that is prechecked, depending on what the user selects early in the form. Here’s the code to write the prechecks for reference. It works perfectly. Whenever a new prechecking happens cause by user selection => postback

        DataTable DefaultActivity = GetData();
        // Resets checkboxes to blank in between postbacks
        for (int p = 0; p < CheckBoxList1.Items.Count; p++)
        {
            CheckBoxList1.Items[p].Selected = false;
        }
        // Fills in the prechecked boxes
        if (DefaultActivity.Rows.Count > 0)
        {
            int SelectedRoleID = Int32.Parse(RadioButtonList2.SelectedValue);
            for (int i = 0; i < DefaultActivity.Rows.Count; i++)
            {
                int DatabaseRoleID = Convert.ToInt32(DefaultActivity.Rows[i]["roleid"]);
                if (SelectedRoleID == DatabaseRoleID)
                {
                    int DatabaseActivityID = Convert.ToInt32(DefaultActivity.Rows[i]["activityid"]);
                    for (int j = 0; j < CheckBoxList1.Items.Count; j++)
                    {
                        if (DatabaseActivityID == Convert.ToInt32(CheckBoxList1.Items[j].Value))
                        {
                            CheckBoxList1.Items[j].Selected = true;
                        }
                    }
                }
            }
        }

The problem I’m having is that the user should be able to check more boxes in addition to the prechecked boxes, but when they click the Submit Button, it does not detect the newly checked boxes. Here’s the Submit Button code.

        // Data into the request table
        SqlConnection sqlConn = new SqlConnection("Server=x;Database=x;User=x;Password=x;Trusted_Connection=False;");
        string Statement = "INSERT INTO table (x) OUTPUT INSERTED.requestid VALUES (x)";
        SqlCommand sqlComm = new SqlCommand(Statement, sqlConn);

        // Grabs the auto-created RequestID to forward to the next page
        sqlComm.Connection.Open();
        string RequestID = Convert.ToString((Int32)sqlComm.ExecuteScalar());
        sqlComm.Connection.Close();
        sqlComm.Connection.Dispose();

        // Data into the x table
        SqlConnection ActivitysqlConn = new SqlConnection("Server=x;Database=x;User=x;Password=x;Trusted_Connection=False;");
        string ActivityStatement = "INSERT INTO table (x) VALUES (x)";
        for (int k = 0; k < CheckBoxList1.Items.Count; k++)
        {
            if (CheckBoxList1.Items[k].Selected == true)
            {
                SqlCommand ActivitysqlComm = new SqlCommand(ActivityStatement, ActivitysqlConn);
                ActivitysqlComm.Connection.Open();
                ActivitysqlComm.ExecuteNonQuery();
                ActivitysqlComm.Connection.Close();
            }
        }
        Response.Redirect("nextscreen.aspx?RequestID=" + RequestID);

Any ideas why the submit button can’t see the new checks? It reads the prechecks fine. Side question- is there a more efficient way to Opening/Closing the connections? Be nice, I’m new 🙂

  • 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-08T07:45:09+00:00Added an answer on June 8, 2026 at 7:45 am

    Easy fix- I moved the prechecking code from PageLoad to the RadioButtonList, the object which affects the prechecking. Now all the prechecks and additional checks are properly saved.

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

Sidebar

Related Questions

I have a site which has an area that requires authentication. Right now I
I have a site set up in ASP.NET MVC3 right now, but the layout
I have a web site written in asp.net 4.0. Right now the connection stirng
We have a classic ASP site that is been hosted in IIS 7.5. I
I have the following code, deployed on a https Asp site, build with MVC
I have a ASP.NET MVC site that is locked down using Forms Authentication. The
Brief introduction: I have this ASP.NET Webforms site with the particularity that it doesn't
I have a line of C# in my ASP.NET code behind that looks like
I have written a user control for our SharePoint site that builds an HTML
I have an asp.net website that is nearing release. The site deals with business

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.