2013-01-17 29 views
-1

下面的代碼的偉大工程的是:任何想法如何將數組轉換爲FOR循環?

dashboard1.Text = charArray(0) 
dashboard2.Text = charArray(1) 
dashboard3.Text = charArray(2) 
dashboard4.Text = charArray(3) 
dashboard5.Text = charArray(4) 
dashboard6.Text = charArray(5) 
dashboard7.Text = "" 
dashboard8.Text = "" 
dashboard9.Text = "" 
dashboard10.Text = "" 
If dashboardl >= 7 Then 
    dashboard7.Text = charArray(6) 
End If 
If dashboardl >= 8 Then 
    dashboard8.Text = charArray(7) 
End If 

If dashboardl >= 9 Then 
    dashboard9.Text = charArray(8) 
End If 
If dashboardl >= 10 Then 
    dashboard10.Text = charArray(9) 
End If 

不過,我想將它們轉換成for循環下面的例子中,但我得到的錯誤。

For i = 1 To (dashboardl) 
     ("dashboard" & CStr(i)) = charArray(i - 1) 
Next i 

非常感謝您的協助。

+0

[在VB.NET中創建控制數組](http://msdn.microsoft.com/en-us/library/aa289500(v = vs .71).aspx) –

回答

3

你可以試試這個...

For i = 1 To dashboardl 
     Dim txtBox As TextBox = FindControl("dashboard" & i) 
     txtBox.Text = charArray(i - 1) 
    Next i 
0

哈,我錯過了點。仍然沒有在真正的計算機上,但嘗試這...

For i = 1 To dashboardl 
    Me.Controls("dashboard" & CStr(i)).Text = charArray(i - 1) 
Next i 
+0

Brian,謝謝你們的幫助。我收到一個錯誤,即文本不是System.Web.UI.Control的成員。我在html表單上使用RadioButtonList。 會像formName.SelectedValue = charArray(i - 1) 工作嗎? –