How to retrieve data from Dynamic Textboxes?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have dynamically created n number of text boxes in a form like txtQL(1),
txtQL(2) , ...txtQL(n)
How can I retrieve the values in a loop? I'm confused as to how to approach
this! Please help.

I get the error "Referenced object has a value of 'Nothing'". as indicated in
the code below:

For Each c In Controls
If i < maxRow Then
Error txtQLLink(i) = c.FindControl("txtQLLink(" + i & ")")
txtQLUrl(i) = c.FindControl("txtQlUrl(" + i & ")")
If txtQLLink(i).Text <> "" Then
textQLHtml = textQLHtml & txtQLUrl(i).Text & txtQLLink(i).Text
strQL = strQL & txtQLLink(i).Text & "," & txtQLUrl(i).Text
i += 1
End If
End If
Next


Thanks for your time.
 
OK. It works now.

For Each c In Controls
If i < maxRow Then
Dim strTextBoxId = "txtQLLink" + "(" + i.ToString + ")"
txtQLLink(i) = c.FindControl(strTextBoxId)
txtQLUrl(i) = c.FindControl("txtQlUrl" + "(" + i.ToString + ")")
If txtQLLink(i).Text <> "" Then
strQL = strQL & txtQLLink(i).Text & "," & txtQLUrl(i).Text
If i < maxRow Then
strQL = strQL & ","
End If
i += 1
End If
End If
Next
 
Back
Top