[英]How to get a List values in VB.NET? (GridView works well but I need to access each value instead)
這是我的方法,如果我將它綁定在 GridView 中,效果很好,如下所示: GridView1.DataSource = Me.GetTags
Partial Class backoffice_posts_Edit
Private Function GetTags() As List(Of Tag)
Dim constring As String = ConfigurationManager.ConnectionStrings("AccessConnectionString1").ConnectionString
Using con As New SqlConnection(constring)
Using cmd As New SqlCommand("SELECT tag_id FROM tags_tbl WHERE tag_choice = 1", con)
Dim tags As New List(Of Tag)
cmd.CommandType = CommandType.Text
con.Open()
Using sdr As SqlDataReader = cmd.ExecuteReader()
While sdr.Read()
tags.Add(New Tag With {
.tagId = Convert.ToInt32(sdr("tag_id"))
})
End While
End Using
con.Close()
Return tags
End Using
End Using
End Function
End Class
Public Class Tag
Public Property tagId As Integer
End Class
但不是使用 GridView,我需要遍歷列表值(如果標簽值是例如 23 則稍后應用條件......)
所以我做了以下但不幸的是這個打印tag;tag;tag;tag;tag;tag;
而不是價值觀:
For Each element In Me.GetTags
Response.Write(element)
Response.Write(";")
Next
For Each element In Me.GetTags
Response.Write(element.tagId)
Response.Write(";")
Next
或者
For Each tagId In Me.GetTags().Select(Function(t) t.tagId)
這是來自@41686d6564standsw.Palestine 的正確答案
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.