當且僅當選中gridview中的複選框時,纔有發送電子郵件的gridview。VB.net Foreach不會增加
我的gridview循環工作正常;然而,當我在我的數組環行調試線,很明顯的是,i
從未從0
隨着你所看到的,我甚至想增加i
,但它並沒有幫助[我知道我不該'不得不增加i
,但我想嘗試一些]。
有什麼建議嗎?
全局變量:
Public arrayLength As Integer
Public email_list As String() = New String(arrayLength) {}
循環:
'set array length
For Each gvrow As GridViewRow In DisplaySup.Rows
If gvrow.RowType = DataControlRowType.DataRow Then
Dim chkRow As CheckBox = TryCast(gvrow.Cells(0).FindControl("SelectUser"), CheckBox)
If chkRow.Checked Then
count = count + 1
End If
End If
Next
'update public variable
arrayLength = count
For Each gvrow As GridViewRow In DisplaySup.Rows
Dim CheckBox1 As CheckBox = DirectCast(gvrow.FindControl("SelectUser"), CheckBox)
For Each row As GridViewRow In DisplaySup.Rows
For i As Integer = 0 To email_list.Length - 1
If row.RowType = DataControlRowType.DataRow Then
Dim chkRow As CheckBox = TryCast(row.Cells(0).FindControl("SelectUser"), CheckBox)
If chkRow.Checked Then
oneProvided = True
Dim v_comp As String = row.Cells(2).Text.ToString()
strSearch = "Select email_val from table_name where company = '" & v_comp & "'"
Dim SupStr As OleDbCommand = New OleDbCommand(strSearch, conn)
Dim OracleDataAdapterAds As OleDbDataAdapter = New OleDbDataAdapter
OracleDataAdapterAds.SelectCommand = SupStr
Dim DsAds As DataSet = New DataSet
DsAds.Clear()
OracleDataAdapterAds.Fill(DsAds, "table_name")
email = DsAds.Tables(0).Rows(0).Item(0)
email_list(i) = email
'i = i + 1
End If
End If
Next
Next
元素的數量由我的例子中的變量'arrayLength'決定。元素的數量是基於檢查多少行創建的計數值 – narue1992
我調試並查看'count'是否正確,'arrayLength'但是如果我調試'? email_list.Length'我總是得到1? – narue1992
嗯,我認爲它應該用作邊界,因爲我有線'arrayLength =計數'和全局變量使用arrayLength @MattWilko – narue1992