62,046
社区成员
发帖
与我相关
我的任务
分享
protected void Button2_Click(object sender, EventArgs e)
{
List<Department> list = new List<Department>();//实体集合
Department depart = new Department();//实体
foreach (GridViewRow dr in GridView1.Rows)
{
// cell[i]就是CheckBox所在的列,从0开始
if ((dr.Cells[0].FindControl("CheckBox1") as CheckBox).Checked)
{
// 这个方法是根据主键查实体 cells[4]就是主键所在列,你看看你的gridview,id在哪一列,从0开始
depart = dm.GetDepartMentById(Convert.ToInt32(dr.Cells[4].Text));
list.Add(depart);
this.GridView3.DataSourceID = "";
this.GridView3.DataSource = list;
this.GridView3.DataBind();
}
}
}
While i < Me.GridView1.Rows.Count
If (CType(Me.GridView1.Rows(i).FindControl("cb"), CheckBox).Checked = True) Then
End If
i += 1
End While