需要帮助调整我的逻辑一点点。打破foreach循环
,你看,我有两个foreach loop
两者的不同列在GridView控件 这个代码是在OnRowUpdating在GridView更多信息正是我在做什么,你可以看到在关闭线程here
的问题是:
在每一个循环我将更新一行数据库,但由于我有两个不同的循环,它不会退出,直到第一个循环完成。
举一个例子:我有_rpt.Count = 2,所以它会循环两次,然后它击中第二个循环。
GridViewRow row = gv.SelectedRow;
Repeater _rpt = gv.Rows[e.RowIndex].Cells[8].FindControl("rptReg") as Repeater;
Repeater _rpt1 = gv.Rows[e.RowIndex].Cells[9].FindControl("rptVisitor") as Repeater;
foreach (RepeaterItem item in _rpt.Items)
{
TextBox _txt = item.FindControl("txtId") as TextBox;
TextBox _txt1 = item.FindControl("txtName") as TextBox;
//update db
}
foreach (RepeaterItem item1 in _rpt1.Items)
{
TextBox _txt3 = item1.FindControl("txtVisitor") as TextBox;
//update db
}
有没有一种方法可以读取两个foreach循环值?
由于`_txt3`赋值在`if`块内,所以更新错误。您需要将任何引用放在`if`块的范围内,否则确保在使用之前将其分配给它。 – Jaymz 2011-01-27 17:01:01