如何使多行记录在gridview中显示为一行

时间:2013-10-19 23:24:46

标签: vb.net gridview entity-framework-4 group-by

你好请遇到linq到实体的问题。我正在研究学校管理系统。我可以从数据库中生成每个学生的记录和学生的分数,并将其绑定到gridview控件。以下是我用于生成学生成绩的代码

    Dim subjectSearch = From subSearch In DemoSchool.EssenceSubjectRegistrations Where subSearch.Session = drpSession.SelectedItem.Text _
                    AndAlso subSearch.Term = drpTerm.SelectedItem.Text AndAlso subSearch.RealClass.ClassSN = findClassSN.FirstOrDefault AndAlso _
                     subSearch.SubjectCode = drpSubject.SelectedValue _
                     Select New With {.SubjectRegSN = subSearch.SubjectRegSN,
                                     .FirstName = subSearch.Student.FirstName,
                                     .Surname = subSearch.Student.Surname,
                                      .CA1 = subSearch.CA1,
                                       .CA2 = subSearch.CA2,
                                       .CA3 = subSearch.CA3,
                                       .CA4 = subSearch.CA4,
                                       .CA5 = subSearch.CA5,
                                       .CA6 = subSearch.CA6,
                                       .CA7 = subSearch.CA7,
                                       .CA8 = subSearch.CA8,
                                       .CA9 = subSearch.CA9,
                                       .CA10 = subSearch.CA10,
                                     .Exam = subSearch.Exam}

执行此操作后,我会对结果执行此查询,以通过执行此操作来计算某些虚拟列的结果

    Dim secSubjectSearch = (From jamie In subjectSearch Select jamie).ToList() _
                          .Select(Function(jamie) New With {.SubjectRegSN = jamie.SubjectRegSN,
                          .FirstName = jamie.FirstName,
                          .Surname = jamie.Surname,
                           .CA1 = jamie.CA1,
                            .CA2 = jamie.CA2,
                            .CA3 = jamie.CA3,
                            .CA4 = jamie.CA4,
                            .CA5 = jamie.CA5,
                            .MidTerm = CDbl(jamie.CA1 + jamie.CA2 + jamie.CA3 + jamie.CA4 + jamie.CA5) / 5,
                            .CA6 = jamie.CA6,
                            .CA7 = jamie.CA7,
                            .CA8 = jamie.CA8,
                            .CA9 = jamie.CA9,
                            .CA10 = jamie.CA10,
                             .Total = CDbl(jamie.CA1 + jamie.CA2 + jamie.CA3 + jamie.CA4 + _
                                      jamie.CA5 + jamie.CA6 + jamie.CA7 + jamie.CA8 + jamie.CA9 + jamie.CA10),
                           .Exam = jamie.Exam})

这个结果与正确显示的网格视图有关。我的问题是每个学生每个科目有三个记录(科目分数一年三次记录为第一学期第二学期和第三学期),这些记录显示为每个学生三个单独的行。我想要一种情况,我可以将每个学生记录只放在一行,这样每个学生在gridview中只有一行,而不是三行。 从过去的五天开始,我真的需要资深专业人士的帮助。一如既往地感谢您的帮助。

0 个答案:

没有答案