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
29 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Asp.Net Session Question 2 36
Many to one in one row 2 40
Import a excel sheet in a grid 2 13
.Net remove carriage returns, line feeds and tabbs 5 14
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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 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