我的 ASP.NET 页面显示了部分databound
网格视图:
<asp:GridView ID="myGridView" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="name" HeaderText="Name" />
<asp:TemplateField HeaderText="Datum" ItemStyle-CssClass="tdRight">
<ItemTemplate>
<asp:TextBox ID="datum" runat="server" Text=""></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Uhrzeit" ItemStyle-CssClass="tdRight">
<ItemTemplate>
<asp:TextBox ID="uhrzeit" runat="server" Text=""></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Ort" ItemStyle-CssClass="tdRight">
<ItemTemplate>
<asp:TextBox ID="ort" runat="server" Text=""></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Hausnummer" ItemStyle-CssClass="tdRight">
<ItemTemplate>
<asp:TextBox ID="hausnummer" runat="server" Text=""></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Gebäude" ItemStyle-CssClass="tdRight">
<ItemTemplate>
<asp:TextBox ID="gebaeude" runat="server" Text=""></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Raumnummer" ItemStyle-CssClass="tdRight">
<ItemTemplate>
<asp:TextBox ID="raumnummer" runat="server" Text=""></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
这些TextBoxes
将用用户输入填充,然后作为列添加到 a DataTable
:
DataTable inputData = new DataTable();
inputData.Columns.Add(new DataColumn("datum", typeof(String)));
inputData.Columns.Add(new DataColumn("uhrzeit", typeof(String)));
inputData.Columns.Add(new DataColumn("ort", typeof(String)));
inputData.Columns.Add(new DataColumn("hausnummer", typeof(String)));
inputData.Columns.Add(new DataColumn("gebaeude", typeof(String)));
inputData.Columns.Add(new DataColumn("raumnummer", typeof(String)));
foreach(DataRow row in myGridView.Rows) {
foreach(DataColumn col in row.ItemArray) {
DataRow dr = inputData.NewRow();
dr["datum"] = ((TextBox) myGridView.FindControl("datum")).Text;
dr["uhrzeit"] = ((TextBox) myGridView.FindControl("uhrzeit")).Text;
dr["ort"] = ((TextBox) myGridView.FindControl("ort")).Text;
dr["hausnummer"] = ((TextBox) myGridView.FindControl("hausnummer")).Text;
dr["gebaeude"] = ((TextBox) myGridView.FindControl("gebaeude")).Text;
dr["raumnummer"] = ((TextBox) myGridView.FindControl("raumnummer")).Text;
inputData.Rows.Add(dr);
printRow(dr);
}
}
如何访问textareas
,从每个获取文本并将输入数据附加到DataTable
用于创建每一行的?