日期:2014-05-18 浏览次数:20600 次
DataSet ds = new DataSet();
DataTable Course = new DataTable("Course");
Course.Columns.Add("Id", typeof(System.Int32));
Course.Columns.Add("Name", typeof(System.String));
Course.Rows.Add(1, "ASP.NET");
ds.Tables.Add(Course);
DataTable Student = new DataTable("Student");
Student.Columns.Add("Id", typeof(System.Int32));
Student.Columns.Add("Name", typeof(System.String));
Student.Columns.Add("Age", typeof(System.Int32));
Student.Columns.Add("courseId", typeof(System.Int32));
Student.PrimaryKey = new DataColumn[] { Student.Columns["Id"] };
ds.Tables.Add(Student);
Student.Rows.Add(1, "王伟", 20, 1);
Student.Rows.Add(2, "李伟", 18, 1);
Student.Rows.Add(3, "刑天", 18, 1);
DataRelation rel = new DataRelation("relTable",
new DataColumn[] { Course.Columns["Id"] },
new DataColumn[] { Student.Columns["courseId"] });
ds.Relations.Add(rel);
DataView dv = new DataView();
dv.Table = ds.Tables["Student"];
dv.RowFilter = "max(Child(relTable).Age) > 0";
GridView1.DataSource = dv;
GridView1.DataBind();
dv.Table = ds.Tables["Student"];
dv.RowFilter = "max(Child(relTable).Age) > 0";
=>
dv.Table = ds.Tables["Course"];
dv.RowFilter = "max(Child(relTable).Age) > 0";