Solved

Concatenate 2 strings to make variable name

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Name space syntax error 12 43
Resolve Dependency Issues 4 47
Angular JS Route 3 52
When should I use a controller? 3 19
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
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, f…

920 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

12 Experts available now in Live!

Get 1:1 Help Now