Click here to Skip to main content
15,908,834 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good day All, I need your help, I want to generate Position from a list of record for a particular user



C#
//I have a table Named Mark 
MarkID     UserId      SubjectName      TotalScore
1           20            English         60.00
2           21            English         70.00
3           20             Maths          80.00
4           21             Maths          80.00

// From the Table above i want to automatically generate Subject position for each each user in a gridview like this
MarkID     UserId      SubjectName      TotalScore     Postition
1           20            English         60.00         2
3           20             Maths          80.00         1

How do i automatically generate the subject position on it

Normally this is what i have tried so far to get the list of a particular record
var acc  = from c in cdc.Marks where c.userId = "20" select c).tolist();
gridview1.datasource = acc;
gridview.datindind();

//The above code only generate the student records and displays it on a gridview but automatically generating Position without is what i am looking for.. Please your help is really needed..

Thanks in advance


What I have tried:

//I have a table Named Mark
MarkID UserId SubjectName TotalScore
1 20 English 60.00
2 21 English 70.00
3 20 Maths 80.00
4 21 Maths 80.00

// From the Table above i want to automatically generate Subject position for each each user in a gridview like this
MarkID UserId SubjectName TotalScore Postition
1 20 English 60.00 2
3 20 Maths 80.00 1

How do i automatically generate the subject position on it

Normally this is what i have tried so far to get the list of a particular record
var acc = from c in cdc.Marks where c.userId = "20" select c).tolist();
gridview1.datasource = acc;
gridview.datindind();
Posted
Updated 4-Jul-16 1:49am

1 solution

Hi,

Use an order by clause in the LINQ statement you are access the EF with. Below is a reference from the MSDN - ironically based on somebody else's homework.

orderby clause (C# Reference)[^]

..
 
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