未定义类型"ListItem". [英] Type 'ListItem' is not defined.
本文介绍了未定义类型"ListItem".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
For Each item As ListItem In ListBox1.Items
If item.Selected Then
Try
cmd.Parameters("@coursename").Value = item.Text
cmd.ExecuteNonQuery()
Catch ex As Exception
Label1.Text = ex.Message
End Try
End If
Next
推荐答案
只需将代码替换为:
Just replace your code with:
Dim oitem as Object = Nothing
For Each oitem In ListBox1.Items
MsgBox(oitem.ToString())
Next
有关更多信息,请访问: http://msdn.microsoft.com/zh-CN -us/library/system.windows.forms.listbox.items.aspx#Y570 [
More at: http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.items.aspx#Y570[^]
问题是not tagged with the UI type
.
我认为UI type may be Windows Forms
,因为ASP.NET ListBox
控件的Items
属性返回System.Web.UI.WebControls.ListItemCollection
如此处 http://msdn所述. microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.items(v=vs.90) [ http://msdn.microsoft所述. com/en-us/library/system.web.ui.webcontrols.listitemcollection(v = vs.90) [ http://stackoverflow.com/questions/873944/asp-net-display从列表中选择项目ox-in-textbox [ ^ ]而不会产生错误.
对于Windows Forms UI type
,ListBox
控件的Items
属性返回System.Windows.Forms.ListBox.ObjectCollection
,如此处 ^ ],其元素不是ListItem
类型,并且可能是上述错误的原因.
如果要求获取only the selected items
,那么我认为SelectedItems
属性在此处 ^ ]可以用于此目的,如下所示:
The question isnot tagged with the UI type
.
I think theUI type may be Windows Forms
, since theItems
property ofASP.NET ListBox
control returnsSystem.Web.UI.WebControls.ListItemCollection
as explained here http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.items(v=vs.90)[^], which is a collection ofListItem objects
as explained here http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listitemcollection(v=vs.90)[^] and they can be iterated usingListItem
as shown here http://stackoverflow.com/questions/873944/asp-net-display-selected-items-from-listbox-in-textbox[^] without generating the error.
In case ofWindows Forms UI type
, theItems
property ofListBox
control returnsSystem.Windows.Forms.ListBox.ObjectCollection
as explained here http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.items[^], the elements of which are not ofListItem
type and this may be the reason for the above error.
If the requirement is to getonly the selected items
, then I think theSelectedItems
property explained here http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.selecteditems[^] can be used for this purpose as shown below:
For Each item As Object In ListBox1.SelectedItems
Try
cmd.Parameters("@coursename").Value = item.ToString()
cmd.ExecuteNonQuery()
Catch ex As Exception
Label1.Text = ex.Message
End Try
Next
请参阅此网站
http://social.msdn.microsoft.com/Forums/否/vbgeneral/thread/355eb437-d66c-4310-87ea-0b4ba05e0acb [
Refer this site
http://social.msdn.microsoft.com/Forums/no/vbgeneral/thread/355eb437-d66c-4310-87ea-0b4ba05e0acb[^]
这篇关于未定义类型"ListItem".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文