Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get values from a table row of textboxes into a List of objects , from ContentPlaceholder
    primarykey
    data
    text
    <p>I have a table of blank textboxes on a page, if the user puts anything in any of the textboxes I want to save that information in a list of objects. None of these are required, if they enter anything in any row, I want to capture it. Here is the object:</p> <pre><code>public class Siblings { public string SiblingName { get; set; } public string SiblingSchool { get; set; } public string SiblingID { get; set; } } </code></pre> <p>Here is the table:</p> <pre><code>&lt;asp:Content ID="SiblingContent" ContentPlaceHolderID="ContentPlaceHolderSibling" runat="server" &gt; &lt;asp:Panel ID="SiblingInformation" runat="server" ViewStateMode="Inherit" Visible="False" &gt; &lt;table id="SiblingTable" runat="server" &gt; &lt;tr&gt; &lt;td class="header"&gt; &lt;asp:Label ID="SiblingNameLabel" runat="server" Text="Sibling Full Name" &gt;&lt;/asp:Label&gt; &lt;/td&gt; &lt;td class="header"&gt; &lt;asp:Label ID="SiblingSchoolLabel" runat="server" Text="Sibling School"&gt;&lt;/asp:Label&gt; &lt;/td&gt; &lt;td class="header"&gt; &lt;asp:Label ID="SiblingIDLabel" runat="server" Text="Sibling ID"&gt;&lt;/asp:Label&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="field"&gt; &lt;asp:TextBox ID="SiblingName1" runat="server" &gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;td class="field"&gt; &lt;asp:TextBox ID="SiblingSchool1" runat="server" &gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;td class="field"&gt; &lt;asp:TextBox ID="SiblingID1" runat="server" &gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="field"&gt; &lt;asp:TextBox ID="SiblingName2" runat="server" &gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;td class="field"&gt; &lt;asp:TextBox ID="SiblingSchool2" runat="server" &gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;td class="field"&gt; &lt;asp:TextBox ID="SiblingID2" runat="server" &gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="field"&gt; &lt;asp:TextBox ID="SiblingName3" runat="server" &gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;td class="field"&gt; &lt;asp:TextBox ID="SiblingSchool3" runat="server" &gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;td class="field"&gt; &lt;asp:TextBox ID="SiblingID3" runat="server" &gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/asp:Panel&gt; </code></pre> <p></p> <p>And here is what I have so far in my attempt to get the users data into an object list (I had to do this one step at a time to help myself understand what is happening, please consolidate if you like):</p> <pre><code> ContentPlaceHolder mpContentPlaceHolder; Panel siblingPanel; Table siblingTable; TextBox tbox; int i = 1; mpContentPlaceHolder = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolderSibling") as ContentPlaceHolder; if (mpContentPlaceHolder != null) { siblingPanel = (Panel)mpContentPlaceHolder.FindControl("SiblingInformation") as Panel; if (siblingPanel != null) { siblingTable = (Table)siblingPanel.FindControl("SiblingTable"); if (siblingTable != null) { foreach (TableRow tr in siblingTable.Rows) { foreach (TableCell tc in tr.Cells) { foreach (Control c in tc.Controls) { if (c.GetType() == typeof(TextBox)) { tbox = (TextBox)c; if (!(String.IsNullOrWhiteSpace(tbox.Text))) { AllSiblings[i].SiblingName = tbox.Text; } } } } } } } } </code></pre> <p>What I want to have after this is completed is a session for each sibling object, so I can access them later from another ContentPlaceholder. I've tried to give the textboxes ID's that lend themselves to determining is this is a name, school or ID, but I'm not sure how to make use of that. Thank you--</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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