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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Check number of row prior to displaying gridview 10 62
hbo knew my windows software 4 62
Amazon RDS migrate to SQL Server 3 24
How to filter by key press ? 6 19
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

856 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