【发布时间】:2011-09-20 05:41:52
【问题描述】:
我正在尝试将 New List(Of KeyValuePair(Of String, Integer)) 绑定到 listView 目前,我有一个代码关闭:
Dim TestList As List(Of KeyValuePair(Of String, Integer))
For Each key in GetTPDesc (Which is a list of strings)
TestList.Add(New KeyValuePair(Of String, Integer)(GetTPDesc.ToString, 0))
Next
For Each ArtFailedPair in Table
TestAddIndex = ArtFailedPair.Failed
If TestAddIndex <> 0 Then
TestList(TestAddIndex -1) = New KeyValuePair(Of String, Integer)(TestList(TestAddIndex -1).Key, TestList(TestAddIndex -1).Value +1)
End If
Next
对不起,代码块很长,我知道实现很脏,我使用 KeyValuePair 列表的原因是由于需要基于索引的集合,字典没有像我想的那样提供我将。 然后我尝试绑定:
listView.DataSource = TestList
listView.DataBind()
当然,ItemTemplate 有 Eval("key") 和 Eval("value")。但它给了我一个错误,它告诉我: System.Data.Objects.ObjectQuery'1[System.String] 而不是 GetTPDesc。 而且我还认为一个不正确的整数值,因为它似乎不正常。 谢谢。
GetTPDesc:
Dim GetTPDesc = (From tpProducts In context.TestResultLim
Where tpProducts.Art_no = productNumber
Order By tpProducts.TP_no
Select tpProducts.TP_desc)
【问题讨论】:
标签: asp.net vb.net listview webforms