Solved

Concatenate 2 strings to make variable name

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
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 …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

13 Experts available now in Live!

Get 1:1 Help Now