设计原则是这样的,因为用户在录入的时候需要选择若干品种,所以想用个GRID或者表格的控件显示出所有品种,后面的数据直接输入。
格式如下:
====================
品种 | 数据 |
====================
品种1 | TEXTBOX |
====================
品种2 | TEXTBOX |
====================
品种3 | TEXTBOX |
====================
我用DATAGRID绑定了品种这个字段,数据是绑定的一个模板列,在显示的时候是一个TEXTBOX,HTML代码如下:
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 336px; POSITION: absolute; TOP: 168px"
runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="品种" ReadOnly="True" HeaderText="品种"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="数据">
<ItemTemplate>
<asp:TextBox id=TextBox1 runat="server" Text=<%# DataBinder.Eval(Container, "DataItem.数据") %>>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
我用一个按纽来批量提交所有录入的数据,问题是提交的时候如何获取DATAGRID所有行的TEXTBOX的值,并且对应到每个品种,写入数据库。请高手指点一下,或者有没有比较方便的用于ASP。NET下的数据录入的表格控件,前提是可以绑定品种。
just iterate throught DataGrid1.Items collection, if you are use DataSet/DataTable directly, you can consider to retrieve the data from the database first, then move the user changes into the datatable, then user a DataAdapter to update the database
foreach (DataGridItem dgi in DataGrid1.Items)
{
TextBox t = dgi.FindControl("TextBox1") as TextBox1;
string s = t.Text;
....
}