Get Data from a table which has been generated programmatically
<p>I am creating a Control Table programmatically and I want after user clicks a button to get the values.</p>

<p>The table has three columns, {Title(<em>DropDownList</em>), FName(<em>TextBox</em>), LName(<em>TextBox</em>)} and two rows.</p>

<p>I am getting the values for FName, LName without problem, but I am getting wrong value for Title, which is a DropDownList. It gives me for both Titles, the selected value of the second column.</p>

<p><strong>More Clear,</strong></p>

<p>For the 1st row --> Mr, Foo, Bar</p>

<p>for 2nd row- -> Mrs, Foo, Bar</p>

<p><strong>after user clicks the button I am getting</strong></p>

<p>For 1st row --> <strong>Mrs</strong>, Foo, Bar</p>

<p>For 2nd row- -> Mrs, Foo1, Bar.</p>

<p>This is the method of table creation </p>

<pre><code>private void SetPassengerDetailsTable(int roomIdentity, int? adults,
        int? children, int? infants, bool setLeader = false) {
        var leaderIsSet = false;
        var roomTable = new Table();
        roomTable.ID = "PassengerDetailsTBL_" + roomIdentity;
        var trHeader = new TableHeaderRow();
        var tcTitle = new TableCell();
        tcTitle.Controls.Add(new Label() { Text = "&lt;b&gt;Title&lt;/b&gt;" });
        trHeader.Cells.Add(tcTitle);

        var tcFName = new TableCell();
        tcFName.Controls.Add(new Label() { Text = "&lt;b&gt;First Name&lt;/b&gt;" });
        trHeader.Cells.Add(tcFName);

        var tcLName = new TableCell();
        tcLName.Controls.Add(new Label() { Text = "&lt;b&gt;Last Name&lt;/b&gt;" });
        trHeader.Cells.Add(tcLName);

        var tcType = new TableCell();
        tcType.Controls.Add(new Label() { Text = "&lt;bType&lt;/b&gt;" });
        trHeader.Cells.Add(tcType);

        roomTable.Rows.Add(trHeader);

        var listItems = new ListItem[6];
        listItems[0] = new ListItem("", "") { Selected = true };
        listItems[1] = new ListItem("Mr", "Mr");
        listItems[2] = new ListItem("Mrs", "Mrs");
        listItems[3] = new ListItem("Miss", "Miss");
        listItems[4] = new ListItem("Infant", "Inf");
        listItems[5] = new ListItem("Child", "Master");


        if (adults != null || adults &gt; 0) {
            for (int i = 1; i &lt;= adults; i++) {
                var trBody = new TableRow();
                var ddl = new DropDownList();
                var leadAdultRowID = setLeader &amp;&amp; !leaderIsSet ? "leadadult" : "adult";
                ddl.ID = "room" + roomIdentity + leadAdultRowID + i + "Title";
                ddl.Items.AddRange(listItems);

                var tcTitleValue = new TableCell();
                tcTitleValue.Controls.Add(ddl);
                trBody.Cells.Add(tcTitleValue);

                var tcFNameValue = new TableCell();
                tcFNameValue.Controls.Add(new TextBox() { ID = "room" + roomIdentity + "adult" + i + "FName", Width = 170 });
                trBody.Cells.Add(tcFNameValue);

                var tcLNameValue = new TableCell();
                tcLNameValue.Controls.Add(new TextBox() { ID = "room" + roomIdentity + "adult" + i + "LName", Width = 170 });
                trBody.Cells.Add(tcLNameValue);

                var tcTypeValue = new TableCell();
                var leadAdult = setLeader &amp;&amp; !leaderIsSet ? "Lead Adult" : "Adult";
                tcTypeValue.Controls.Add(new Label() { Text = leadAdult });
                trBody.Cells.Add(tcTypeValue);
                roomTable.Rows.Add(trBody);

                if (setLeader)
                    leaderIsSet = true;
            }
        }

        if (children != null || children &gt; 0) {
            for (int i = 1; i &lt;= children; i++) {
                var trBody = new TableRow();
                var ddl = new DropDownList();
                ddl.ID = "room" + roomIdentity + "child" + i + "Title";
                ddl.Items.AddRange(listItems);

                var tcTitleValue = new TableCell();
                tcTitleValue.Controls.Add(ddl);
                trBody.Cells.Add(tcTitleValue);

                var tcFNameValue = new TableCell();
                tcFNameValue.Controls.Add(new TextBox() { ID = "room" + roomIdentity + "child" + i + "FName", Width = 170 });
                trBody.Cells.Add(tcFNameValue);

                var tcLNameValue = new TableCell();
                tcLNameValue.Controls.Add(new TextBox() { ID = "room" + roomIdentity + "child" + i + "LName", Width = 170 });
                trBody.Cells.Add(tcLNameValue);

                var tcTypeValue = new TableCell();
                tcTypeValue.Controls.Add(new Label() { Text = "Child" });
                trBody.Cells.Add(tcTypeValue);
                roomTable.Rows.Add(trBody);
            }
        }

        if (infants != null || infants &gt; 0) {
            for (int i = 1; i &lt;= infants; i++) {
                var trBody = new TableRow();
                var ddl = new DropDownList();
                ddl.ID = "room" + roomIdentity + "infan" + i + "Title";
                ddl.Items.AddRange(listItems);

                var tcTitleValue = new TableCell();
                tcTitleValue.Controls.Add(ddl);
                trBody.Cells.Add(tcTitleValue);

                var tcFNameValue = new TableCell();
                tcFNameValue.Controls.Add(new TextBox() { ID = "room" + roomIdentity + "infan" + i + "FName", Width = 170 });
                trBody.Cells.Add(tcFNameValue);

                var tcLNameValue = new TableCell();
                tcLNameValue.Controls.Add(new TextBox() { ID = "room" + roomIdentity + "infan" + i + "LName", Width = 170 });
                trBody.Cells.Add(tcLNameValue);

                var tcTypeValue = new TableCell();
                tcTypeValue.Controls.Add(new Label() { Text = "Infant" });
                trBody.Cells.Add(tcTypeValue);
                roomTable.Rows.Add(trBody);
            }
        }
        PassengerDetailsPH.Controls.Add(roomTable);
    }
</code></pre>

<p>Thanks</p>
