Solved

Concatenate 2 strings to make variable name

Posted on 2009-04-02
3
403 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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

815 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now