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
36 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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

734 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