Persisting Table data in ASP .NET
<p>am populating a table dynamically, which includes a checkbox with an id  associated with it and then display it to the user. I do not have problems with the display part. 
After the user checks some specified checkboxes and hits the submit button, I would like to get his choices, Checkbox that is checked and its associated Id but during postback, my table neither has  any of the rows I added dynamically nor does it have of the user's selection. Any help is deeply appreciated.</p>

<p>Cheers
Ip Doh</p>

<p>My aspx page is as follows</p>



<p></p>

<pre><code>&lt;asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true"   runat="server"&gt;
&lt;/asp:ScriptManager&gt;
&lt;asp:UpdatePanel ID="UpdatePanel1" runat="server"&gt;
    &lt;ContentTemplate&gt;
        &lt;asp:Label ID="dummyLabel" runat="server" Text="Label"&gt;&lt;/asp:Label&gt;
        &lt;asp:Button ID="submitButton"  onclick="async_Click" runat="server" Text="Submit" /&gt;

         &lt;asp:Table ID="usrTable"  EnableViewState="true" runat="server"&gt;
        &lt;asp:TableHeaderRow&gt;
            &lt;asp:TableHeaderCell Text="Id"/&gt;
            &lt;asp:TableHeaderCell Text="Customer Name"/&gt;
        &lt;/asp:TableHeaderRow&gt;
    &lt;/asp:Table&gt;
    &lt;/ContentTemplate&gt;

&lt;/asp:UpdatePanel&gt;
</code></pre>

<p></p>

<hr>

<p>I have the following in the code file</p>

<pre><code>    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            CreateTable();
        }
if (IsPostBack)
        {
            List&lt;int&gt; choices = GetUserChoices();

            //Do Something with user choices
        }



    }


protected List&lt;int&gt; GetUserChoices()
    {
        List&lt;int&gt; choices = new List&lt;int&gt;();
        foreach (TableRow row in usrTable.Rows)
        {
            CheckBox cb = row.Controls[0] as CheckBox;

            if ((cb != null) &amp;&amp; (cb.Checked))
            {
                choices.Add(int.Parse(cb.Text));
            }
        }

        return choices;
    }

    void CreateTable()
    {
        dummyLabel.Text = DateTime.Now.ToString();
        for (int i = 0; i &lt; 3; i++)
        {
            TableCell cell1 = new TableCell();            
            CheckBox cb = new CheckBox();
            cb.Text = i.ToString();
            cb.AutoPostBack = true;
            cb.EnableViewState = true;
            cell1.Controls.Add(cb);

            TableCell cell2 = new TableCell();
            cell2.Text = String.Format("Clm : {0} - Row : {1}", 2, i);

            TableRow row = new TableRow();
            row.Cells.Add(cell1);
            row.Cells.Add(cell2);

            usrTable.Rows.Add(row);
        }
    }
</code></pre>

<p>The label value is persisted, whereas my table does not have any rows that i added.</p>
