Asp.net 如何将ListItemCollection转换为(对象的)列表
我定义了一个类,比如Asp.net 如何将ListItemCollection转换为(对象的)列表,asp.net,vb.net,Asp.net,Vb.net,我定义了一个类,比如 Public Class MyClass Public Type1 As Integer Public Type2 As float End Class 如何将ListItemCollection转换为(MyClass的)列表 使用Linq: Dim selectedItems As List(Of [MyClass]) = ListItemCollectionInstance.Items.Cast(Of [MyClass])().Where(Function(itm
Public Class MyClass
Public Type1 As Integer
Public Type2 As float
End Class
如何将ListItemCollection转换为(MyClass的)列表
使用Linq:
Dim selectedItems As List(Of [MyClass]) = ListItemCollectionInstance.Items.Cast(Of [MyClass])().Where(Function(itm) itm.Selected = True).ToList()
VB.NET中的
MyClass
是关键字,而float
类型是通过Single
别名(System.Single)表示的
我已经用样本数据构建了集合
Dim cl作为新的ListItemCollection
cl.Add(新列表项(“1”、“1.2”))
cl.Add(新列表项(“2”、“2.3”))
cl.Add(新列表项(“3”、“3.4”))
Dim lst=从cl中的ele选择新_
项目与
{
.Type1=Integer.Parse(ele.Text),
.Type2=Single.Parse(ele.Value)
}
对于lst中作为项目的每个ele
响应。写入(“
”和ele.Type1&“&ele.Type2)
下一个
@user1460625&AVD:看看标签,asp.net说…@Quandary,标签是在AVD的评论之后添加的。
Dim selectedItems As List(Of [MyClass]) = ListItemCollectionInstance.Items.Cast(Of [MyClass])().Where(Function(itm) itm.Selected = True).ToList()
Public Class Item
Public Type1 As Integer
Public Type2 As Single
End Class
Dim cl As New ListItemCollection
cl.Add(New ListItem("1", "1.2"))
cl.Add(New ListItem("2", "2.3"))
cl.Add(New ListItem("3", "3.4"))
Dim lst = From ele In cl Select New _
Item With
{
.Type1 = Integer.Parse(ele.Text),
.Type2 = Single.Parse(ele.Value)
}
For Each ele As Item In lst
Response.Write("<br/> " & ele.Type1 & " " & ele.Type2)
Next