我是 vb 的新手,如果我的问题之前被问过,我很抱歉。我已经搜索过,但未能找到或识别出答案。我正在使用 Visual Studio 2010 并在 vb.net 中创建一个应用程序。我有 2 个名为问题和答案的数组。我想同时遍历这 2 个数组并从这 2 个数组中检索记录。我正在使用以下代码。
Dim sql As String = "SELECT QuestionId,Answer FROM tbl_Answers"
Dim dt As DataTable = obj.GetDTbl(sql)
For Each row As DataRow In dt.Rows
SelectedAnswers += row("Answer").ToString & ","
Next
Dim Questions() As String = QuestionsIds.Split(",")
For Each question In Questions
Dim answers() As String = SelectedAnswers.Split(",")
For Each answer In answers
Dim rbl As RadioButtonList = DirectCast(plcHolderForm.FindControl("Question_" & question), RadioButtonList)
rbl.SelectedIndex = rbl.Items.IndexOf(rbl.Items.FindByValue("answer".ToString))
在上面的代码中,显然可以看出我的外部 for 循环只执行一次。我需要为每个循环遍历 2 以上,以便针对每个问题,我可以获得通过 FindByValue 函数检索的答案