简体   繁体   English

VB.net For Loop从多个控件捕获数据(CheckBoxList项目)

[英]VB.net For Loop to capture data from multiple controls (CheckBoxList Items)

I have two CheckBoxList controls ( chkListVideoMedia and chkListAudioMedia ) on my page that I want to capture information from and insert the records into the database. 我的页面上有两个CheckBoxList控件( chkListVideoMediachkListAudioMedia ),我想从中捕获信息并将记录插入数据库。 I have it working for one of the controls, I just need help modifying my code below to include the second CBL 我已将其用于其中一个控件,我只需要帮助修改下面的代码以包含第二个CBL

Dim values As New ArrayList()
For counter As Integer = 0 To chkListVideoMedia.Items.Count - 1
    If chkListVideoMedia.Items(counter).Selected Then
        MyTextBox.Text = chkListVideoMedia.Items(counter).Value
        values.Add(newId)
    End If
Next
If values.Count > 0 Then
  For item As Integer = 0 To values.Count - 1
    If item = 0 Then
      MyMedia1.Text = values(item).ToString
    End If
    If item = 1 Then
      MyMedia2.Text = values(item).ToString
    End If
    If item = 2 Then
      MyMedia3.Text = values(item).ToString
    End If
    If item = 3 Then
      MyMedia4.Text = values(item).ToString
    End If
  Next
End If

Thanks, James 谢谢,詹姆斯

You can find out which Collection has the most Items, then check to make sure that count is not greater than the maximum Items in each collection. 您可以找出哪个Collection具有最多Items,然后检查以确保计数不大于每个collection中的Maximum Items。 Something like this. 这样的事情。

Dim values As New ArrayList()
Dim counter As Integer
If chkListVideoMedia.Items.Count > chkListAudioMedia.Items.Count Then
    counter = chkListVideoMedia.Items.Count - 1
Else
    counter = chkListAudioMedia.Items.Count - 1
End If
For x = 0 To counter
    If Not (counter > chkListVideoMedia.Items.Count - 1) Then
        'Do your work here
    End If
    If Not (counter > chkListAudioMedia.Items.Count - 1) Then
        'Do your work here
    End If
Next

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM