Data organization issue

sammySeltzer
sammySeltzer used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Ryan ChongSoftware Team Lead

Commented:
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

Top Expert 2011

Author

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
Ryan ChongSoftware Team Lead

Commented:
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.
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

Top Expert 2011

Author

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.
Software Team Lead
Commented:
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.
Top Expert 2011

Author

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.
Top Expert 2011

Author

Commented:
Thank you

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial