【问题标题】:How do I access Checkbox list variables using VB in Visual Studio?如何在 Visual Studio 中使用 VB 访问复选框列表变量?
【发布时间】:2014-04-04 20:24:02
【问题描述】:

如何使用 Visual Basic 从 Visual Studio 中的复选框列表控件中检索值? 目前我正在使用“Reason.Text”,但我需要检索所有检查过的变量。

【问题讨论】:

    标签: asp.net vb.net visual-studio checkboxlist


    【解决方案1】:

    你的意思是这样的吗

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
         Dim st As String = String.Empty
         For Each item As Object In Me.CheckedListBox1.CheckedItems
              st += item.ToString & vbCrLf
         Next
         MessageBox.Show(st)
    End Sub
    

    【讨论】:

      【解决方案2】:

      看看这个简单的示例:

      这里是按钮代码:

       Protected Sub btnGetValues_Click(sender As Object, e As EventArgs) Handles btnGetValues.Click
      
          Dim Sb As New System.Text.StringBuilder
      
      
          'to get al values using linq reaons.items as Listitem which expose selected property and you may filter on this
          'property too as per my example
          Dim X = (From a As ListItem In reason.Items Where a.Selected = True Select a.Value).ToList
          For Each el In X
              Sb.Append(el.ToString & "<br/>")
          Next
          lit1.Text = Sb.ToString
          Sb.Clear()
      
      
          'to get anonymous type with multiples params you may use this:
          Dim k = (From a As ListItem In reason.Items Where a.Selected = True Select New With {.Checked = a.Selected, .TextValue = a.Text, .IDValue = a.Value}).ToList
      
          For Each el In k
              Sb.Append(String.Format("IsSelected=<b>{0}</b>, TextNameValue=<b>{1}</b>, IntegerValue=<b>{2}</b><br/>", el.Checked, el.TextValue, el.IDValue))
          Next
          lit2.Text = Sb.ToString
          Sb.Clear()
          Sb = Nothing
      
      
      End Sub
      

      如果它正是您要搜索的标记为已回答

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-06
        • 1970-01-01
        • 2017-09-13
        • 2020-03-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多