Data organization issue

Greetings again mates.

When I run the following code:

If dtCurrentTable.Rows.Count > 0 Then
                '//Next collection. Spouse Information
                For Each row As DataRow In dtCurrentTable.Rows

                    Dim txtsourcen As String = TryCast(row.ItemArray(1), String)
                    Dim txtsourcea As String = TryCast(row.ItemArray(2), String)
                    Dim txtsourcei As String = TryCast(row.ItemArray(3), String)


                    lblPreviewSourceName.Text += txtsourcen & "<br />"
                    lblPreviewSourceAddress.Text += txtsourcea & "<br />"
                    lblPreviewIncomeSource.Text += txtsourcei & "<br />"


                    'get the values from the TextBoxes

                    'then add it to the collections with a comma "," as the delimited values

                    sc.Add(lblPreviewSourceName.Text + "," + lblPreviewSourceAddress.Text + "," + lblPreviewIncomeSource.Text)
                    rowIndex += 1
                Next

Open in new window

, I get this result and the way it is presented.

Name: Ivory West
Indiana Jones

Address: 20 Ivory Street
65 Kay Dr

Income: 1000001
5820000 

Open in new window


I am getting that result because we are dynamically creating rows. In this case, there are two rows relating to same field names.

I would like the data to be presented in the following format:

Name: Ivory West
Address: 20 Ivory Street
Income: 1000001

Name: Indiana Jones
Address: 65 Kay Dr
Income: 5820000 

Open in new window


What do I need to change in the code I posted to get this type of lay out?

Thank you.
LVL 29
sammySeltzerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
the existing labels are printing the data at property level (like: Name, Address, Income) and now you want to print the data at record level (group those properties together).

hence, you may just need to use one label with this code: (not really tested, you may customize accordingly)

			If dtCurrentTable.Rows.Count > 0 Then
                '//Next collection. Spouse Information
				
				Dim output As String = "";
				lblPreviewSourceName.Text = ""
				
                For Each row As DataRow In dtCurrentTable.Rows

                    Dim txtsourcen As String = TryCast(row.ItemArray(1), String)
                    Dim txtsourcea As String = TryCast(row.ItemArray(2), String)
                    Dim txtsourcei As String = TryCast(row.ItemArray(3), String)
					
                    output = "Name: " & txtsourcen & "<br />Address: " & txtsourcea & "<br />Income: " & txtsourcei & "<br />"
					
                    lblPreviewSourceName.Text += output & "<br />"

                    sc.Add(lblPreviewSourceName.Text + "," + lblPreviewSourceAddress.Text + "," + lblPreviewIncomeSource.Text)
                    rowIndex += 1
                Next
			End If	

Open in new window

0
sammySeltzerAuthor Commented:
Thank you Ryan.

It is very close to the solution I am looking for.

Please see screenshot of what I am getting.

I have circled the one little issue to need to be addressed.

The results is what I am looking for but it leaves an extra Address and Income text.
needre.png
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
i believe what you highlighted was generated by label controls: lblPreviewSourceAddress and lblPreviewIncomeSource.

you can try to set its value to "" or directly remove it if they're unused.
0
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

sammySeltzerAuthor Commented:
I believe you meant this line:

 sc.Add(lblPreviewSourceName.Text + "," + lblPreviewSourceAddress.Text + "," + lblPreviewIncomeSource.Text)

Open in new window


I was thinking the same thing and so I removed them and changed that line to this:

                 
  sc.Add(lblPreviewSourceName.Text)

Open in new window


but they are still there. That's why I posted back because I am not sure what else could be causing.
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
regarding your codes:

 sc.Add(lblPreviewSourceName.Text + "," + lblPreviewSourceAddress.Text + "," + lblPreviewIncomeSource.Text)

Open in new window

I'm not sure what is the object type of sc . It would be good if you can tell me that?

in your ASPX front end page, you can directly remove the controls: lblPreviewSourceAddress and lblPreviewIncomeSource if they're unused.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sammySeltzerAuthor Commented:
I removed those from the HTML markup and seems good enough; just some cosmetic stuff that I will work out.

Thank you for your help.
0
sammySeltzerAuthor Commented:
Thank you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.