我在页面上有一个空白文本框表,如果用户在任何文本框中放置任何内容,我想将该信息保存在对象列表中。这些都不是必需的,如果他们在任何一行输入任何内容,我想捕获它。这是对象:
public class Siblings
{
public string SiblingName { get; set; }
public string SiblingSchool { get; set; }
public string SiblingID { get; set; }
}
这是表格:
<asp:Content ID="SiblingContent" ContentPlaceHolderID="ContentPlaceHolderSibling" runat="server" >
<asp:Panel ID="SiblingInformation" runat="server" ViewStateMode="Inherit" Visible="False" >
<table id="SiblingTable" runat="server" >
<tr>
<td class="header">
<asp:Label ID="SiblingNameLabel" runat="server" Text="Sibling Full Name" ></asp:Label>
</td>
<td class="header">
<asp:Label ID="SiblingSchoolLabel" runat="server" Text="Sibling School"></asp:Label>
</td>
<td class="header">
<asp:Label ID="SiblingIDLabel" runat="server" Text="Sibling ID"></asp:Label>
</td>
</tr>
<tr>
<td class="field">
<asp:TextBox ID="SiblingName1" runat="server" ></asp:TextBox>
</td>
<td class="field">
<asp:TextBox ID="SiblingSchool1" runat="server" ></asp:TextBox>
</td>
<td class="field">
<asp:TextBox ID="SiblingID1" runat="server" ></asp:TextBox>
</td>
</tr>
<tr>
<td class="field">
<asp:TextBox ID="SiblingName2" runat="server" ></asp:TextBox>
</td>
<td class="field">
<asp:TextBox ID="SiblingSchool2" runat="server" ></asp:TextBox>
</td>
<td class="field">
<asp:TextBox ID="SiblingID2" runat="server" ></asp:TextBox>
</td>
</tr>
<tr>
<td class="field">
<asp:TextBox ID="SiblingName3" runat="server" ></asp:TextBox>
</td>
<td class="field">
<asp:TextBox ID="SiblingSchool3" runat="server" ></asp:TextBox>
</td>
<td class="field">
<asp:TextBox ID="SiblingID3" runat="server" ></asp:TextBox>
</td>
</tr>
</table>
</asp:Panel>
到目前为止,这是我尝试将用户数据放入对象列表中的内容(我必须一次执行此步骤以帮助自己了解正在发生的事情,如果您愿意,请合并):
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;
}
}
}
}
}
}
}
}
完成后我想要的是每个兄弟对象的会话,因此我可以稍后从另一个 ContentPlaceholder 访问它们。我试图为文本框提供 ID,以便确定这是名称、学校还是 ID,但我不知道如何使用它。谢谢 -