错误无法转换类型为' System.String'的对象输入SimpleImageUpload

时间:2014-08-15 21:59:45

标签: vb.net image

我遇到了将字符串转换为类型SimpleImageUpload of piczard的问题,这是一个可以上传图片的控件。如果有人遇到这个问题,我会希望得到一些帮助....

在我的代码中,我正在抓取ImageUploaderPerson1.ID.ToString(),我正在尝试将其分配给SimpleImageUpload,以便稍后进行操作。

这是我的代码:

Dim Pictures As New Hashtable
Dim pic As DictionaryEntry
Dim retValPic As SimpleImageUpload = New SimpleImageUpload()
Dim button As String = hfPictureIndex.Value
PictureInfo.PictureIndex = Convert.ToInt16(button)
Pictures.Add("1", ImageUploaderPerson1.ID.ToString())
Pictures.Add("2", ImageUploaderPerson2.ID.ToString())

For Each pic In Pictures
    If pic.Key.ToString() = button.ToString() Then

        retValPic = pic.Value '*trying to convert it here!

        '** Saving Picture
        If retValPic.HasImage Then
        End If
Next

1 个答案:

答案 0 :(得分:0)

尝试使用对实际对象的引用而不是哈希表的字典。

Dim Pictures As New Dictionary(Of String, SimpleImageUpload)
Dim retValPic As SimpleImageUpload = New SimpleImageUpload()
Dim button As String = hfPictureIndex.Value
PictureInfo.PictureIndex = Convert.ToInt16(button)
Pictures.Add("1", ImageUploaderPerson1)
Pictures.Add("2", ImageUploaderPerson2)

For Each pic as KeyValuePair(Of String, SimpleImageUpload) In Pictures
    If pic.Key.ToString() = button.ToString() Then

        retValPic = pic.Value '*trying to convert it here!

        '** Saving Picture
        If retValPic.HasImage Then
        End If
Next