Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're searching for a non-existing ID. </p> <p>First you're setting the Id of the control to just a number (j) and later you'll try to find it with with a search to "chk"+the number j.</p> <p>2 options here: </p> <p>Change <code>chk.ID = j.ToString();</code> to <code>chk.ID ="chk" + j.ToString();</code></p> <p>or</p> <p>Change <code>CheckBox cb = (CheckBox)Page.FindControl("chk" + j);</code> to <code>CheckBox cb = (CheckBox)Page.FindControl(j);</code></p> <p>Personally I would go for the first option since naming a control with just a number wouldn't be a good idea.</p> <p><strong>UPDATE</strong></p> <pre><code>for (int j = 1; j &lt;= days - 1; j++) { ... chk = new CheckBox(); chk.ID = j.ToString(); chk.AutoPostBack = true; // chk.Checked = true; lbl = new Label(); lbl.Text = startDate.ToString("dd/MM/yyyy"); lbl.ID = j.ToString(); PlaceHolder1.Controls.Add(lbl); PlaceHolder1.Controls.Add(chk); PlaceHolder1.Controls.Add(new RadioButton { }); PlaceHolder1.Controls.Add(new LiteralControl("&lt;BR&gt;")); startDate = startDate.AddDays(1); //No need fot this. You still have the object chk from a few lines above // CheckBox cb = (CheckBox)Page.FindControl("chk" + j); //If you want to use this, put these lines before you add the control. //chk.Checked = CheckBox1Checked; //chk.oncheckedchanged += CheckBox1OnChecked; //You should declare this outside the for-loop or even outside the method //if you want to use it elsewhere int chkcount = 0; //Here you are using the correct object. //chk.Checked should reflect exactly what you've set above. if (chk.Checked) { chkcount++; } int chkcount1 = chkcount; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload