for (int k = 0; k < data.Rows.Count; k++)//循环每一行
{
string str = "";
for (int i = 0; i < data.Rows[i].Cells.Count; i++)//循环每一列
{
str += data.Rows[k].Cells[i].ToString() + " ";//把每列中的数据添加到str中
}
//执行sql语句 把str插入到指定数据库表中
//....
}
先对GridView进行遍历
然后再根据是否选定执行相应的操作
for (int i = 0; i < GridView1.Rows.Count;i++ )
{
CheckBox check = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
if (check.Checked)
{
//这里放你要执行的代码
}
}
foreach (GridviewItem itm in yourGridView.items)
{
itm.FindControl("control id");
}
when you find your control,you can use it to do everything.