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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:38:32+00:00 2026-05-21T05:38:32+00:00

I’m working on slightly changing the functionality of a page in an ASP.Net website.

  • 0

I’m working on slightly changing the functionality of a page in an ASP.Net website. In the original page there was a checkbox list written into the page with no items hard coded.

Instead on the initial render the cbl gets databound to the results of a query thus:

sSQL = "select query here";

using (SqlConnection dbcon = new DataAccess().OpenDb())
{
     using (SqlDataReader dr = new SqlCommand(sSQL, dbcon).ExecuteReader())
     {
          cbl.DataTextField = "description";
          cbl.DataValueField = "productid";
          cbl.DataSource = dr;
          cbl.DataBind();
     }
     dbcon.Close();
}

On a postback the following code:

foreach (ListItem li in cbl.Items) { if (li.Selected) rtnQS += li.Value + ","; }

Happily goes through the dynamic databound list items in the checkbox list and retrieves the checked values. I tried to do the same thing, putting an empty table on the page and then creating the rows dynamically:

sSQL = "similar select query here";

using (SqlConnection dbcon = new DataAccess().OpenDb())
{
    using (SqlDataReader dr = new SqlCommand(sSQL, dbcon).ExecuteReader())
    {
       while (dr.Read())
       {
           TableRow tr = new TableRow();

           TableCell tc = new TableCell();

           CheckBox chk = new CheckBox();

           chk.Text = dr["description"].ToString();
           chk.InputAttributes.Add("id", dr["id"].ToString());
           chk.Checked = true;

           tc.Controls.Add(chk);

           TableCell tc2 = new TableCell();

           if (Convert.ToBoolean(dr["controlcondition"]))
           {
                CheckBoxList cbl_sub = new CheckBoxList();
                cbl_sub.Attributes.Add("for", dr["id"].ToString());
                sSQL = "subquery";
                using (SqlConnection newcon = new DataAccess().OpenDb())
                {
                   using (SqlDataReader br = new SqlCommand(sSQL, newcon).ExecuteReader())
                   {
                       cbl_block.DataTextField = "subname";
                       cbl_block.DataValueField = "subid";
                       cbl_block.DataSource = br;
                       cbl_block.DataBind();
                   }
                }

                tc2.Controls.Add(cbl_sub);
           }
           else
           {
              TextBox txtSub = new TextBox();
              txtSub.Attributes.Add("for", dr["id"].ToString());

              tc2.Controls.Add(txtSub);
           }

           tr.Cells.Add(tc);
           tr.Cells.Add(tc2);

           tblDispatchOpt.Rows.Add(tr);
        }
    }

    dbcon.Close();
}

The only problem is that when the iterator comes to the table it only reads the hard coded header row. (The table renders beautifully with all the correct attributes on the original page though.)

Here’s the bit of code that tries to read the table rows:

foreach (TableRow row in tblDispatchOpt.Rows)
{
      TableCell cell = row.Cells[0];

      ++counter;

      foreach (Control c in cell.Controls)
      {
           if (c is CheckBox)
           {
               CheckBox cb = (CheckBox)c;
               if (cb.Checked && cb.Attributes["ttid"] != null) dtTTInfo.Rows.Add(cb.Attributes["ttid"].ToString(), "", "");
           }
      }
}

Except that a debugging label check happily tells me there’s only one row and it’s the hard coded header row. So essentially doesn’t read the other rows as it seems the page doesn’t believe they exist when it comes to read them.

So why doesn’t it work with the table? Or, if it doesn’t work with the table for the usual reason that things don’t work with dynamic controls on postbacks e.g. rendering, lifecycle etc., why does it work with the checkboxlist?

  • 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-05-21T05:38:33+00:00Added an answer on May 21, 2026 at 5:38 am

    You have to recreate dynamic controls on every postback if you want to get values from them.
    You should do that in CreateChildControls() method.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm making a simple page using Google Maps API 3. My first. One marker
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to loop through a bunch of documents I have to put

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.