看下面的数据按总分来排列,但总分中有相同的,所以排名就要相同排名 教师名 总分
第1名 张三 85
第2名 李四 69
第3名 王五 69
第4名 吴六 69
第5名 刘七 68 如何才能把数据变成:
排名 教师名 总分
第1名 张三 85
第2名 李四 69
第2名 王五 69
第2名 吴六 69
第3名 刘七 68
第1名 张三 85
第2名 李四 69
第3名 王五 69
第4名 吴六 69
第5名 刘七 68 如何才能把数据变成:
排名 教师名 总分
第1名 张三 85
第2名 李四 69
第2名 王五 69
第2名 吴六 69
第3名 刘七 68
产生下一行时,将总分与该viewstate比较,如果相同,排名与rows(e.rowindex-1)的值相同,
如果不相同,排名加1,最后将改行的总分覆盖掉viewstate
If Not IsPostBack Then
viewstate("total")="" '初始化总分
viewstate("piac")=0 '初始化排名
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上面的代码不一定能编译成功,能理解思路就好