我在 db 中有一个包含多个用逗号分隔的值的列,现在我想编辑它,所以我从 db 中检索值,将其分开并将其存储在字符串数组中,然后生成文本框并将值分配给文本框现在我想检索更新的生成的文本框中的值是代码
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'