Solved

How to loop through all the text controls on the web form and store the value in an array

Posted on 2014-10-28
4
17 Views
Last Modified: 2016-06-15
I have a web form with has two dropdown list items. But at run time, I dynamically add the 5 text box controls to the form.

Now I want to read the data entered in these 5 text boxes into an array so that I could then loop through the array to save it to the SQL server table.

I am proficient in VB and request a sample VB code that handles my request.

Thank you all in advance.
0
Comment
Question by:Peter Drespel
  • 2
4 Comments
 
LVL 2

Expert Comment

by:Glen Richmond
ID: 40408746
as its only 5 objects why not address them directly?

MyArray(1)=myObject1.Text
MyArray(2)=myObject2.Text
MyArray(3)=myObject3.Text
MyArray(4)=myObject4.Text
MyArray(5)=myObject5.Text
0
 

Author Comment

by:Peter Drespel
ID: 40408776
To further explain, I wish to let you know that the 5 objects that are created at run time are read from a table. The table hold the name of the control and the label that it should display.

For eg.

ID, CONTROL_NAME, CONTROL_LABEL, FORM_ID
1,'Customer_ID','Customer ID',1
2,'Customer_Name','Customer Name' ,1
3,'Customer_ID','Customer ID',2
4,'Customer_Name','Customer Name' ,2
5,'Amount','Amount',2

etc

So I read the database to paint the html for the web form.  The controls are not fixed, it depends on the rows in the table.

Now how can i assign myObject1.text since the myobject1 in my form_id=1 is Customer_id
0
 
LVL 2

Accepted Solution

by:
Glen Richmond earned 500 total points
ID: 40408806
ok dont know the exact syntax, but a For Each should do it

idxA=1
For Each MyCtrl In MyFrm
    If TypeOf MyCtrl Is TextBox Then
        MyArray(idxA) = MyCtrl.Text    
        idxA=idxA+1
    End If
Next MyCtrl

Open in new window

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

757 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

24 Experts available now in Live!

Get 1:1 Help Now