以下代码可行,请大家看看还有没有别的更多高效的办法,谢谢!
DataTable dt = new DataTable();
dt.Columns.Add("YiGongID",typeof(string));
dt.Columns.Add("XingMing", typeof(string));
foreach (GridViewRow item in this.GridView1.Rows)//取出有打勾的..id
{
CheckBox ckb = item.FindControl("CheckBox1") as CheckBox;
if (ckb.Checked)
{
LinkButton MyLinkButton = item.FindControl("LinkButton1") as LinkButton;
DataRow dr = dt.NewRow();
dr["YiGongID"] = GridView1.DataKeys[item.RowIndex].Value.ToString();
dr["XingMing"] = MyLinkButton.Text;
dt.Rows.Add(dr);
}
}
DataView dv = new DataView(dt);
this.GridView2.DataSource = dv;
GridView2.DataBind();