程序员的部落

导航

checkbox gridview指定数据并保存到table中

DataTable dt = new DataTable();
DataColumn dc = new DataColumn("列1", typeof(System.String));
dt.Columns.Add(dc);
dc = new DataColumn("列2", typeof(System.String));
dt.Columns.Add(dc);
dc = new DataColumn("列3", typeof(System.String));
dt.Columns.Add(dc);
foreach (GridViewRow currow in GridView1.Rows )
{
CheckBox cb = currow.FindControl("CheckBox1") as CheckBox;
if (cb.Checked)
{
DataRow dr = dt.NewRow();
dr["列1"] = currow.Cells[0].Text;
dr["列2"] = currow.Cells[1].Text;
dr["列3"] = currow.Cells[2].Text;
dt.Rows.Add(dr);
}
}

posted on 2009-04-02 10:19  程序员的部落  阅读(175)  评论(0编辑  收藏  举报