日期:2014-05-17 浏览次数:20906 次
DataTable dt1 = new DataTable(); dt1.Columns.Add("id", typeof(int)); dt1.Rows.Add(1); dt1.Rows.Add(2); DataTable dt2 = dt1.Clone(); dt2.Rows.Add(11); dt2.Rows.Add(12); DataTable dt = new DataTable(); dt.Merge(dt1); dt.Merge(dt2); DataSet ds = new DataSet(); ds.Tables.Add(dt); ds.Tables.Add(dt1); ds.Tables.Add(dt2); DataRelation dataRelation1 = new DataRelation(null, dt.Columns[0], dt1.Columns[0]); DataRelation dataRelation2 = new DataRelation(null, dt.Columns[0], dt2.Columns[0]); ds.Relations.Add(dataRelation1); ds.Relations.Add(dataRelation2); dt.Rows[0]["id"] = 100; //修改合并表中原表1的某个值 dt.Rows[3]["id"] = 9999; //修改合并表中原表2的某个值 GridView1.DataSource = dt1; GridView1.DataBind(); GridView2.DataSource = dt2; GridView2.DataBind(); GridView3.DataSource = dt; GridView3.DataBind();