We help IT Professionals succeed at work.

Data organization issue

176 Views
Last Modified: 2017-03-28
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

CERTIFIED EXPERT

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
CERTIFIED EXPERT

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.
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.
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
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