| |

VerySource

 Forgot password?
 Register
Search
View: 704|Reply: 7

A question about GridView sorting

[Copy link]

3

Threads

17

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-2-1 22:00:02
| Show all posts |Read mode
See the following data arranged by total score, but the total score is the same, so the rankings must be the same

Rank Teacher name Total score
1st Zhang San 85
2nd place Li Si 69
# 3 Wang Wu 69
# 4 Wu Liu 69
5th Liu Qi 68

How can I turn the data into:
Rank Teacher name Total score
1st Zhang San 85
2nd place Li Si 69
2 Wang Wu 69
# 2 Wu Liu 69
3 Liu Qi 68
Reply

Use magic Report

0

Threads

43

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 China

Post time: 2020-3-17 20:00:01
| Show all posts
For records with the same total score, is there any requirement for sorting? It should be casual, but the value of the "rank" column is the same.
Reply

Use magic Report

3

Threads

17

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

 Author| Post time: 2020-3-17 22:30:01
| Show all posts
Yes
Reply

Use magic Report

0

Threads

43

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 Italy

Post time: 2020-3-18 15:30:01
| Show all posts
Set ds.defaultview.sort = "total score"&"desc"

In the OnRowDataBound process, put the total score into a viewstate,
When the next row is generated, the total score is compared with the viewstate. If they are the same, the ranking is the same as the value of rows (e.rowindex-1).
If they are not the same, add 1 to the ranking, and finally overwrite the total score of the new line with viewstate
Reply

Use magic Report

3

Threads

17

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

 Author| Post time: 2020-3-19 21:00:01
| Show all posts
Can you make it clear
Reply

Use magic Report

0

Threads

43

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 China

Post time: 2020-3-22 19:30:01
| Show all posts
Page_Load:
If Not IsPostBack Then
  viewstate ("total") = "" 'Initialize the total score
  viewstate ("piac") = 0 'Initial ranking
end if


rowdatabound:
If e.Row.RowType = DataControlRowType.DataRow then
   if e.Row.Cells (2) .Text = viewstate ("total") then
      e.row.Cells (0) .text = viewstate ("piac")
   else
      viewstate ("piac") = viewstate ("piac") + 1
      e.row.Cells (0) .text = viewstate ("piac")
   end if
   viewstate ("total") = e.Row.Cells (2) .Text
end if

The above code may not compile successfully, just understand the idea
Reply

Use magic Report

3

Threads

14

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-3-26 02:15:01
| Show all posts
It seems to continue according to the total score, `` He has three total scores are the same ''
It seems like it should come out the same`
Reply

Use magic Report

3

Threads

17

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

 Author| Post time: 2020-8-13 12:00:01
| Show all posts
There is still a compilation error...
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list