Click here to Skip to main content
15,916,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Please i have a project that i query the database using entity framework as my ORM. This is my query

VB
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}



Then i query my result so that i can be able to do some operation on it by doing this

C#
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})


The result of the second query is bounded to the gridview which renders properly as it is suppose to rendered. My problem is that i want to create a virtual column called Rank on the gridview after the .MidTerm bounded column that will display the position of each person record in the search result.


These are my gridview column
NAME       CA1      CA2      CA3     CA4     CA5    MIDTERM       RANK
James       50        50      60      40      60      52          3
Essty       100       50      50      50      50      60          2
Markus      100       40      50      60      50      60          2
Code        100       100     100     100     50      90          1


Above is a format of the gridview columns. I want rank to be a virtual column that is calculated based on the midterm score of the students.Code VB scored 90 so his rank so be 1 and so on.Please i don't know how to calculate this rank column and the code to get the highest and the smallest.Really i need help thanks
Posted
Updated 23-Oct-13 23:34pm
v4

1 solution

This is how i finally made it work.
Have a RANK field and pre-calculate it and bound it, something like:

        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,
               .RANK = -1}).ToList()
        dim sorted = secSubjectSearch.Select(function(n) n.MidTerm).Distinct().OrderByDescending(function(n) n).ToList()
        for each itm in secSubjectSearch
            itm.RANK = sorted.IndexOf(itm.MidTerm) + 1
        next

This answer was provided by @Rex on Stackoverflow http://stackoverflow.com/questions/19562115/how-to-create-a-virtual-column-on-a-gridview-based-on-a-particular-gridview-colu[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900