结合ForEach循环和ListItems

时间:2018-08-14 15:39:25

标签: asp.net vb.net

我有几个ForEach循环,这些循环循环检索每个复选框列表中的选中复选框。我试图理解/理解的是如何将ForEach循环组合成一个循环。以下是我目前拥有并正在工作的东西。

    For Each li As ListItem In allocationCheckList.Items
        customReportQueries(li.Value, li.Text, li)
    Next

    For Each li As ListItem In clientSpecificList.Items
        customReportQueries(li.Value, li.Text, li)
    Next

    For Each li As ListItem In dataStructureList.Items
        customReportQueries(li.Value, li.Text, li)
    Next

1 个答案:

答案 0 :(得分:2)

您可以这样合并:

调用块:

Private Sub SomeSub()

    customReportQueries(allocationCheckList.Items)
    customReportQueries(clientSpecificList.Items)
    customReportQueries(dataStructureList.Items)

End Sub

更改customReportQueries子例程

Private Sub customReportQueries(checkBoxList As ListItemCollection)

    For Each li As ListItem In checkBoxList

        'Do what the old customReportQueries Subroutine did

    Next

End Sub