List <string> list = new List <string>(); for(int i = 0;i <dataGridview1.Rows.Count -1;i++) { if(datagridview1.Rows[i].Cells["checkbox列名"].Value == null) { contiue; } if((bool)datagridview1.Rows[i].Cells["checkbox列名"].Value) { list.Add(datagridview1.Rows[i].Cells["ID列"].Value.ToString()) } }/*这是把它ID取出来,其他的操作...........*/
用数组 然后数据库语句就 select .... primarykey in (选中行的主键值) 绑定datagridview ok
string 集合=“”;
for(int i=0;i<gv.rows.cout;i++)
{
if((check)gv.rows[i].findControl("Checkbox")) //判断是否选中
{
if(集合=="")
{
集合=gv.row[i]["主键"].tostring();
}
else
{
集合=","+gv.row[i]["主键"].tostring();
}
}
}if(集合!="")
{
dataset ds=getdataset(select * from 表 where 主键 in ("+主键集合+"));
}
另一个datagridview.datasourse=ds;
另一个datagridview.databind();
List <string> list = new List <string>();
for(int i = 0;i <dataGridview1.Rows.Count -1;i++)
{
if(datagridview1.Rows[i].Cells["checkbox列名"].Value == null)
{
contiue;
}
if((bool)datagridview1.Rows[i].Cells["checkbox列名"].Value)
{
list.Add(datagridview1.Rows[i].Cells["ID列"].Value.ToString())
}
}/*这是把它ID取出来,其他的操作...........*/
{
集合=gv.row[i]["主键"].tostring();
}
else
{
集合=","+gv.row[i]["主键"].tostring();
} } 是因为你有可能是选择多个的,这里是收集你选择的键值和ID