Click here to Skip to main content
14,391,917 members
Rate this:
Please Sign up or sign in to vote.
See more:
<tbody>
                                                               @{int srno2 = 0;}
                                                               @foreach (College.Core.ViewModels.SGPA.ExamsViewModel _Exams in _subject.GetExams())
                                                               {
                                                                   srno2 += 1;
                                                                   <tr>
                                                                       <td>@srno2</td>
                                                                       <td>@_Exams.ExamType</td>
                                                                       <td>@_Exams.ObtainedMark</td>
                                                                       <td>@_Exams.OutOfMarks</td>

                                                                       @if(@_Exams.TotalLectureConducted == null)
                                                                       {
                                                                           <td>0</td>
                                                                       }
                                                                       else
                                                                       {
                                                                           <td>@_Exams.TotalLectureConducted</td>
                                                                       }
                                                                       @if(@_Exams.NoOfLectureAttended == null)
                                                                       {
                                                                           <td>0</td>
                                                                       }
                                                                       else
                                                                       {
                                                                           <td>@_Exams.NoOfLectureAttended</td>
                                                                       }
                                                                       @if(@_Exams.AverageAttendance == null)
                                                                       {
                                                                          <td>0%</td>
                                                                       }
                                                                       else
                                                                       {
                                                                          <td>@_Exams.AverageAttendance%</td>
                                                                       }

                                                                   </tr>
                                                               }
                                                           </tbody>
                                                           <tfoot>

                                                               <tr>
                                                                   <td colspan="4" align="right">Total</td>
                                                                   <td>SUM-TotalLectureConducted</td>
                                                                   <td>SUM-NoOfLectureAttended</td>
                                                                   <td>(SUM-TL/SUM-NLA)*100</td>

                                                               </tr>

                                                           </tfoot>


What I have tried:

NO	Exam 	   Mark	Out	  TL	 NLA	  AV
1	End Tem	   12	60	   5	 5	    100%
2	Internal 1 10	20	   3	 1	    33%
3	internal 2 10	20	   4	 2	    50%
                    Total  12    8	    66%

TL-TotalLectureConducted
NLA-NoOfLectureAttended

I want to this format of result 
please help me
Posted
Updated 3-Dec-19 4:05am
Comments
Richard MacCutchan 30-Nov-19 6:01am
   
Look at your desired outpu. From that you can see how many columns are required and what value each should contain. Your table layout just needs to match those requirements, so write it out on paper before creating your actual code.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Sum the values within the loop, and output the totals in the footer.

Obviously you'll need to calculate the total average from the other totals.
<tbody>
    @{
        int srno2 = 0;
        double tl = 0, nla = 0;
    }
    @foreach (College.Core.ViewModels.SGPA.ExamsViewModel _Exams in _subject.GetExams())
    {
        srno2 += 1;
        tl += _Exams.TotalLectureConducted.GetValueOrDefault();
        nla += _Exams.NoOfLectureAttended.GetValueOrDefault();
        
        <tr>
            <td>@srno2</td>
            <td>@_Exams.ExamType</td>
            <td>@_Exams.ObtainedMark</td>
            <td>@_Exams.OutOfMarks</td>
            <td>@_Exams.TotalLectureConducted.GetValueOrDefault()</td>
            <td>@_Exams.NoOfLectureAttended.GetValueOrDefault()</td>
            <td>@_Exams.AverageAttendance.GetValueOrDefault()%</td>
        </tr>
    }
</tbody>
<tfoot>
    <tr>
        <td colspan="4" align="right">Total</td>
        <td>@tl</td>
        <td>@nla</td>
        
        @if (tl == 0)
        {
            <td>(N/A)</td>    
        }
        else
        {
            double av = nla / tl;
            <td>av.ToString("P")</td>
        }
    </tr>
</tfoot>
   
Comments
Maciej Los 3-Dec-19 9:22am
   
5ed!

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

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100