Solved

Concatenate 2 strings to make variable name

Posted on 2009-04-02
3
406 Views
Last Modified: 2012-05-06
HiI have 6 textboxes on a form, I want to loop through them and if there is a value I want to write this back to a database.

How can I concatenate say "txtAnswer" & 1 to give me txtAnswer1 - a text box name on y form , so I can get the value like this b = txtAnswer1.text.

Or is there another (better) way to loop through the form contols.

Andy
0
Comment
Question by:Andy Green
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 29

Accepted Solution

by:
David H.H.Lee earned 400 total points
ID: 24048165
Hi CarmelinaD,
Try this:

For i as integer=1 to 6
  Dim txtAns as TextBox
  txtAns=Ctype(Page.FindControl("txtAnswer" & i), TextBox)
 
 ' remaining your code here during iteration...
Next
0
 
LVL 8

Assisted Solution

by:Faheem Shaikh
Faheem Shaikh earned 100 total points
ID: 24048166
Try this, it uses the Control property to loop through the form controls:
http://www.extremeexperts.com/Net/Articles/LoopingthroughControls.aspx
 
0
 
LVL 3

Author Closing Comment

by:Andy Green
ID: 31565712
Thanks both. I used X Coms solutions but yours faheem29484 was interesting and i've book marked just in case.

Andy
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question