简体   繁体   English

vb.net列表如何排序和显示

[英]vb.net list how to sort and display

I have a list that is is populated by a DB query: 我有一个由数据库查询填充的列表:

Dim bplist As List(Of KeyValuePair(Of String, Integer)) = New List(Of KeyValuePair(Of String, Integer))

What I want to do is sort the list in order of largest Integer to smallest and then display both Key and Value of this list in the HTML part of my .aspx page. 我要做的是按最大整数到最小的顺序对列表进行排序,然后在我的.aspx页面的HTML部分中显示此列表的键和值。

I've googled around quite a bit and only managed to confuse myself. 我已经在Google上搜索了很多次,但最终还是使自己感到困惑。 Can someone please help me with this? 有人可以帮我吗? Thanks. 谢谢。

You can use a linq query to accomplish this 您可以使用linq查询来完成此操作

dim bplist as List(Of KeyValuePair(Of String, Integer)) = New List(Of KeyValuePair(Of String, Integer))
dim sortedList as List(Of KeyValuePair(Of String, Integer)) = bplist.OrderByDescending(Function(x) x.value).toList

In order to bind the keys and values to HTML, I would suggest taking a look at repeaters 为了将键和值绑定到HTML,我建议看看中继器

Note 注意

This is assuming that when you say you want to sort by the highest to lowest integer, that you are meaning the value 这是假设当您说要按最高到最低整数排序时,您的意思是值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM