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 6141549

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:15:55+00:00 2026-05-23T18:15:55+00:00

I am dynamically creating a table with data and check boxes in it, my

  • 0

I am dynamically creating a table with data and check boxes in it, my problem is when i check to see one specific check-box is checked, out of many, it resets to the default state of false (note: its not just one it doesn’t work with, it works with non of the generated check boxes)

Before i create the page_load function i create the check box, further down i create the table, and populate it with data, then i set up a function to check on a click to see if the box was indeed checked, iv’e tried many iterations of this with no luck

protected void  table_builder(SqlDataReader readerinfo)
{
    //Create a new step for the user
    step3label.Text = "3.";
    //Table header
    TableHeaderRow hr = new TableHeaderRow();
    TableHeaderCell hc = new TableHeaderCell();
    TableHeaderCell hc2 = new TableHeaderCell();
    TableHeaderCell hc3 = new TableHeaderCell();
    hr.Cells.Add(hc);
    hc.Text = "ID"; //Assign header 1 with a name
    hr.Cells.Add(hc2);
    hc2.Text = "Name";//Assign header 2 with a name
    hr.Cells.Add(hc3);
    hc3.Text = "Selection";
    Table1.Rows.Add(hr);


    //Dynamic Table Generation
    int numcells = 3;
    int triswitch = 0;//this is use to chose which cell is made, id, name or selection
    string checkboxID = null;


    while (readerinfo.Read())   //execute the following aslong as there is data to fill the table with
    {
        for (int j = 0; j < 1; j++)
        {
            TableRow r = new TableRow();
            for (int i = 0; i < numcells; i++)
            {
                TableCell c = new TableCell();

                switch (triswitch)
                {
                    case 0: // this case sets the info for the feild id
                        c.Text = readerinfo.GetSqlGuid(0).ToString();
                        checkboxID = readerinfo.GetSqlGuid(0).ToString();
                        r.Cells.Add(c);
                        triswitch = 1;
                        break;

                    case 1:
                        c.Text = readerinfo.GetString(1);
                        r.Cells.Add(c);
                        triswitch = 2;
                        break;

                    case 2:
                        Checkbox_creator(checkboxID,ref c);
                        r.Cells.Add(c);
                        triswitch = 0;
                        break;

                }
            }
            Table1.Rows.Add(r);
        }
    }       
}

protected void Checkbox_creator(string id,ref TableCell send)
{
    //create the checbox
    ckbx = new CheckBox();
    ckbx.ID = "CBX" + checkboxid.ToString();
    checkboxid++;
    ckbx.InputAttributes.Add("value", id);
    send.Controls.Add(ckbx); //add the chekbox to the cell
    checkboxidlist.Add(id);//add the id of the checkbox to the list 
}



//
//AFTER DATATABLE IS LOADED
//

public void test()
{
    // Find control on page.
    CheckBox myControl1 = (CheckBox)Table1.FindControl("CBX0");
    if (myControl1 != null)
    {
        // Get control's parent.
        Control myControl2 = myControl1.Parent.Parent.Parent;
        Response.Write("Parent of the text box is : " + myControl2.ID);
        if (myControl1.Checked == true)
        {
            Response.Write("check box checked");
        }
    }
    else
    {
        Response.Write("Control not found");
    }
}
 //on Submit button click, execute the following function
protected void Submit_Click(object sender, EventArgs e)
{
    //Code to be executed
    string Userinput; //declare Userinput variable
    Userinput = Searchbox.Value; // Set variable to asp controll        
    Response.Write("<br /> <br />"+ Userinput +" <- user imput works");
    ConnectToSql(Userinput);//insert what the user submitted into a query
    test();
    //
    //
    //NoTe code validation is needed to prevent injections
    //  
}
  • 0 0 Answers
  • 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-05-23T18:15:56+00:00Added an answer on May 23, 2026 at 6:15 pm

    add the check boxes to the page before the view state is loaded and the event fires. Do it in the OnInit method not the onload. Use Onload to see if they’re checked or not. Be sure you’re giving them ID’s. Unless this is a partial postback (ajax) then only render the check boxes if !IsPostback

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

Sidebar

Related Questions

I am having a JSP page, where i am dynamically creating a Table data.
I am dynamically creating a table which I want to have clickable rows. When
I am creating a large table dynamically using Javascript. I have realised the time
I am having a table in which i`m dynamically creating and deleting rows. How
I am creating a table (stats_1) dynamically and would like to have each row
I am creating a table dynamically based on the number of rows returned from
I am dynamically creating a table in C# with ASP.NET, and each row will
I am retrieving rows from SQLite table, then dynamically creating an object, and then
I want to create grouped table as dynamically. My aim is creating sections as
I am dynamically creating a table which places a dynamically created radiobuttonlist in each

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.