retreive text from dynamically created texboxes from repeater control selections
<p>I am trying to pass the user selections from the controls generated by a repeater (checkboxes ,dropdownlist, textboxes) to a datatable and use that as a data source to a gridview for testing and eventually to a stored procedure as a table variable parameter . But when there are no selections for some checkboxes the corresponding textboxes are not generated and the code throws an exception -check to determine if the object  is empty before calling the method. the part that seems to be causing the issue is when I pass the text  from the texboxes to the datatable . when I pass the checkbox names it works fine , I am trying to overcome this by checking if the text box control is generated but it still trows the same exception.is there a better way to check if the dynamic textbox is generated?</p>

<pre><code>protected void Button2_Click(object sender, EventArgs e)
{
    DataTable Frs = new DataTable("udtMParameters");
    Frs.Columns.Add("MName", typeof(string));
    Frs.Columns.Add("IsNum", typeof(string));
    Frs.Columns.Add("MValue1", typeof(string));
    Frs.Columns.Add("MValue2", typeof(string));
    try
    {

        foreach (RepeaterItem i in Repeater1.Items)
        {
            CheckBox fn = i.FindControl("chk") as CheckBox;
            CheckBox isn = i.FindControl("ChkboxIsNumeric") as CheckBox;
            PlaceHolder plc = i.FindControl("PlcMFilter") as PlaceHolder;
            TextBox s = i.FindControl("start") as TextBox;
            TextBox l = i.FindControl("end") as TextBox;
            DropDownList d = i.FindControl("value") as DropDownList;


            if (fn.Checked)
            {
                TextBox1.Text = fn.Text;
                if (isn.Checked)
                {
                    DataRow dr = Frs.NewRow();
                    dr["MName"] = fn.Text;
                    dr["IsNum"] = "Y";
                    if (String.IsNullOrEmpty(s.Text))
                    {
                        dr["MValue1"] = s.Text;
                    }
                    else
                    {
                        dr["MValue1"] = " ";
                    }
                    if (String.IsNullOrEmpty(s.Text))
                    {
                        dr["MValue2"] = l.Text;
                    }
                    else
                    {
                        dr["MValue2"] = " ";
                    }

                   Frs.Rows.Add(dr); 
                }

                else
                {
                    DataRow dr = Frs.NewRow();
                    dr["MName"] = fn.Text;
                    dr["IsNum"] = "N";
                    dr["MValue1"] = "MValue1";
                    dr["MValue2"] = "MValue2";
                    Frs.Rows.Add(dr);

                }
            }

            this.GridView1.Visible = true;
            GridView1.DataSource = Frs;
            GridView1.DataBind();


            panel2.Enabled = true;
            panel2.Visible = true;
        }
    }
    catch (Exception ex)
    {
        throw ex;
    }

}
</code></pre>
