Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Concatenate 2 strings to make variable name

Posted on 2009-04-02
3
Medium Priority
?
409 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 1600 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 400 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

926 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