我有一个数据库的列中包含多个值用逗号分隔 现在我想编辑它,所以我检索从数据库分离它的价值,并将其存储在字符串数组 然后生成文本框,并指定值文本框,现在我想从生成文本框 这里获取更新的值是代码检索在asp.net中动态生成的文本框的值
static string[] temp;
static string[] temp1;
static TextBox tbin;
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
barcode_lab.Text = GridView1.SelectedRow.Cells[1].Text;
date_lab.Text = GridView1.SelectedRow.Cells[2].Text;
string tin = GridView1.SelectedRow.Cells[3].Text;
string tout = GridView1.SelectedRow.Cells[4].Text;
//////////////conversion/////////////////////
temp = tin.Split(',');
for (int i = 0; i < temp.Length; i++)
{
tbin = new TextBox();
tbin.Text = temp[i];
tbin.ID = "timein"+i;
PlaceHolder6.Controls.Add(tbin);
PlaceHolder6.Controls.Add(new LiteralControl("<br />"));
}
}
更新:
protected void update_btn_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
foreach (TableCell cell in row.Cells)
{
List<TextBox> textBoxes = MissingExtention.GetAllControls(cell).Where(c => c is TextBox);
}
}
}
public static class MissingExtention
{
public static List<Control> FlattenChildren(this Control control)
{
var children = control.Controls.Cast<Control>();
return children.SelectMany(c => FlattenChildren(c).Where(a => a is TextBox)).Concat(children).ToList();
}
public static List<Control> GetAllControls(Control control)
{
var children = control.Controls.Cast<Control>();
return children.SelectMany(c => FlattenChildren(c)).Concat(children).ToList();
}
}
现在出现以下错误:
- foreach语句无法在类型“System.Web.UI.WebControls.GridView”的变量操作,因为“System.Web.UI.WebControls.GridView”不包含公共定义为“的GetEnumerator”
- 最好重载方法用于匹配“GPServices.MissingExtention.GetAllControls(System.Web.UI.Control)”具有一些无效参数
- 参数1:不能从“的System.Web.UI转换。 ControlCollection'改为'System.Web.UI.Control'