【发布时间】:2015-03-13 20:16:43
【问题描述】:
当调用 Sub 以使用 DictionaryEntry() 中的键和值填充 System.Collections.Generic.Dictionary 时,在调试模式下检查 Dictionary 时,每个属性都有一个带有 X 的红色圆圈并包含文本“无法评估表达式。”它似乎正在工作,如果我尝试添加两个具有相同键/值对的条目,它甚至会抱怨。即使填充了我的测试字符串 (valuesString),也不存在任何键或值。
我从 FormView 的 ItemInserted 事件中调用 Sub(.Net Framework 4,Visual Studio 2013 Webforms 应用程序)
Protected Sub PopulateDictionary(myValues As DictionaryEntry())
Dim de As DictionaryEntry
Dim valuesString As String = String.Empty
Dim myDictionary As New Dictionary(Of String, String)
For Each de In myValues
'This works - the string is populated with key/value pairs
valuesString &= "Key=" & de.Key.ToString() & ", " & _
"Value=" & de.Value.ToString() & "<br/>"
'This doesn't - just get the red circle with an X
myDictionary.Add(de.Key.ToString(), de.Value.ToString())
Next
End Sub
这里发生了什么?我重新启动了 Visual Studio,但没有成功。
【问题讨论】:
-
我确实通过从 SqlDataSourceStatusEventArgs 传入参数集合来解决这个问题。我仍然不确定为什么 Dictionary 无法在 ItemInserted 事件中工作,所以我希望也许有人对此有答案。
标签: asp.net vb.net dictionary webforms