form field collections

  • Thread starter Thread starter sean
  • Start date Start date
S

sean

Hi There,

I am trying to loop through some fields on a form in order to call a stored
procedure to insert bulk information into SQL server, the thing is I am
trying to exit the loop but the loop keeps going past the counter varible. I
only want to insert the information based on the value of the counter, what
am I doing wrong?

Sean


Dim aValues As New ArrayList()
Dim iCount As Integer
Dim counter as Integer

If Page.IsPostBack Then
Dim ctlFormulario, ctlControl As Control
For Each ctlFormulario In Me.Controls

counter += 1

If counter = 5 Then Exit For

response.write (counter = 5)

'If TypeOf (ctlFormulario) Is
System.Web.UI.HtmlControls.HtmlForm Then
If TypeOf (ctlFormulario) Is
System.Web.UI.WebControls.TextBox Then
'For Each ctlControl In ctlFormulario.Controls
For Each ctlControl In ME.Controls

If TypeOf (ctlControl) Is TextBox AND counter <> 5
Then
aValues.Add(CType(ctlControl, TextBox).Text)
' response.write (CType(ctlControl, TextBox).ID & "<BR>")
Response.Write(" " & aValues(iCount) & "<BR>")

iCount += 1


Stored procedure call




End If
Next
End If
Next
End If
 
It could be the statement response.write (counter = 5)
where you may have missed out double quotes, so counter is being assigned a value of 5, which is incremented to 6 in the next pass through the loop, so the condition If counter = 5 never becomes true.

You can try changing the condition to If counter >= 5

Or else it may be the placement of End If for the statement
If counter = 5 then Exit For. Try putting End If immediately after Exit For
Sameeksha,
MCP (.NET)
 
Back
Top