string SelectCommand = string.Format("select top 1 Id, PiaoJuPiaoHao, DaoZhanDianMian, HuoWuPinMing, JianShu, ZhongLiang, TiJi, ZhuangTai, FaZhanDianMian, CheChi from FaZhanPiaoJuBiao");//定义数据样式
bool flag = false;
for (int i = GridView1.Rows.Count-1; i <= GridView1.Rows.Count-1; i--)//从下向上遍历
{
CheckBox box = GridView1.Rows[i].FindControl("CheckBox1") as CheckBox;
flag = box.Checked;
if (flag == true)
{
dt.Tables[0].Rows.RemoveAt(GridView1.Rows[i].RowIndex);
//dt.AcceptChanges();
}
if (i == 0)
{
break;
}
}
GridView1.DataSource = dt.Tables[0];
GridView1.DataBind();
为什么 从下向上遍历呢 因为 数据集再循环中 删除一条语句 其他的索引下标就随着改变 所以 从下向上遍历