i have a column in db which contain multiple values separated by comma now i want to edit it so i retrieve the values from db separate it and store it in string array then generate textboxes and assign the values to textboxes now i want to retrieve the updated values from that generated textboxes here is the code
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 />"));
}
}
UPDATED:
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();
}
}
now the following error occurs:
- foreach statement cannot operate on variables of type 'System.Web.UI.WebControls.GridView' because 'System.Web.UI.WebControls.GridView' does not contain a public definition for 'GetEnumerator'
- The best overloaded method match for 'GPServices.MissingExtention.GetAllControls(System.Web.UI.Control)' has some invalid arguments
- Argument 1: cannot convert from 'System.Web.UI.ControlCollection' to 'System.Web.UI.Control'