日期:2014-05-19  浏览次数:20371 次

我数据库里有10条数据怎么动态绑定到十个文本框里啊?
文本框为   INPUT   TYPE=TEXTBOX   RUNAT   =SERVER
怎么依次绑定到十个文本框内
我用DATASET循环得到十行数据,   而不是10个字段值,请大家注意

------解决方案--------------------
html:

<table width= "400 " cellpadding= "2 ">
<tr>
<td>
<asp:TextBox id= "txt_ww_1 " runat= "server "> </asp:TextBox> </td>
<td>
<asp:TextBox id= "txt_ww_2 " runat= "server "> </asp:TextBox> </td>
<td>
<asp:TextBox id= "txt_ww_3 " runat= "server "> </asp:TextBox> </td>
<td>
<asp:TextBox id= "txt_ww_4 " runat= "server "> </asp:TextBox> </td>
<td>
<asp:TextBox id= "txt_ww_5 " runat= "server "> </asp:TextBox> </td>
</tr>
<tr>
<td>
<asp:TextBox id= "txt_ww_6 " runat= "server "> </asp:TextBox> </td>
<td>
<asp:TextBox id= "txt_ww_7 " runat= "server "> </asp:TextBox> </td>
<td>
<asp:TextBox id= "txt_ww_8 " runat= "server "> </asp:TextBox> </td>
<td>
<asp:TextBox id= "txt_ww_9 " runat= "server "> </asp:TextBox> </td>
<td>
<asp:TextBox id= "txt_ww_10 " runat= "server "> </asp:TextBox> </td>
</tr>
</table>


.cs

if(!IsPostBack)
{
string[] strTextBoxString = { "textbox1 "
, "textbox2 "
, "textbox3 "
, "textbox4 "
, "textbox5 "
, "textbox6 "
, "textbox7 "
, "textbox8 "
, "textbox9 "
, "textbox10 "};

int index = 1;

foreach(string str in strTextBoxString)
{
TextBox tb = (TextBox)this.FindControl( "txt_ww_ " + index);
tb.Text = str;

index ++;
}
}