2.cellformatting 事件 一个个的绑定
//if (e.ColumnIndex == 6)
//{ // e.Value = (e.Value as Grade).GradeName; //} } 第二种方法: model层//查询所有年级信息
public List<Grade> GetGradeList() { string sql = "select * from grades"; DataTable dt= SqlHelper.ExecuteTable(sql, null); List<Grade> grades = new List<Grade>(); for (int i = 0; i < dt.Rows.Count; i++) { Grade g = new Grade(); g.GradeId = Convert.ToInt32(dt.Rows[i]["GradeId"]); g.GradeName = dt.Rows[i]["GradeName"].ToString(); grades.Add(g); } return grades; } DAL层s.GradeId = Convert.ToInt32(dt.Rows[i]["GradeId"]); // students.Add(s); // } // sql = "select COUNT(*) from Students"; // count=Convert.ToInt32( SqlHelper.ExecuteScalar(sql, null)); // return students; //} 在BLL层进行选择for (int i = 0; i < students.Count; i++) { for (int j = 0; j < grades.Count; j++) { if (students[i].GradeId == grades[j].GradeId) { students[i].Grade = grades[j]; break; } } } return students;