请教一个问题
我在页面上放了一个表格控件Table1,通过下面这个函数动态的向Table1中添加textbox
for(int i=1;i<=count;i++)
{
TableRow tRow = new TableRow();
this.Table1.Rows.Add(tRow);
TableCell tCellleft = new TableCell();
tCellleft.Text = "MAC地址" + i.ToString();
tRow.Cells.Add(tCellleft);
TableCell tCellright = new TableCell();
tRow.Cells.Add(tCellright);
TextBox myTextBox = new TextBox();
myTextBox.ID = "txtMac" + i.ToString();
tCellright.Controls.Add(myTextBox);
}
我希望通过下面这个函数将textbox中的字符串连接起来,并且中间有逗号隔开
public string CreateMscString(int count)
{
string strMac = "";
for(int i=1;i<=count;i++)
{
string MacID = "txtMac" + i.ToString();
TextBox txtTemp = new TextBox();
txtTemp = (TextBox)this.Table1.FindControl(MacID);
strMac += txtTemp.Text;
if(i!=count)
strMac += ",";
}
return strMac;
}
但是代码txtTemp = (TextBox)this.Table1.FindControl(MacID)无法找到相应的textbox,请问应该怎么写,谢谢!!
有人说应该写一个递归算法来寻找那些textbox,可我不知道如何写,请不吝赐教,谢谢!!
=================
此问题在CSDN有一些解答,但只提供了思路,仍然无法解决问题
http://expert.csdn.net/Expert/topic/3047/3047670.xml?temp=.4524805
浙公网安备 33010602011771号