Reputation: 3977
Working with DataViews: Is it possible to simply display the rows and column using a string variable instead of a string builder?
The method below gets the rows. However, without a String Builder
appending the values, I am unable to get each row on it's own straight line.
public string DisplayDataRow(DataView dataView)
{
string rows = null;
string lineBreak = "<br />";
foreach(DataRowView rowView in dataView)
{
for(int index = 0; index < dataView.Table.Rows.Count; index++)
rows += rowView.Row[index] + lineBreak;
}
return rows;
}
The rows are returned like this:
1003248739
5
Lykam
Abel
2/11/2015 12:00:00 AM
1003146780
5
Longbine
Abel
2/9/2015 12:00:00 AM
1001136448
1
Cerutti
Abel
2/10/2015 12:00:00 AM
1000854556
2
Roos
Abe
2/10/2015 12:00:00 AM
How do I get an output so that the rows are like this?
1003248739 5 Lykam Abel 2/11/2015 12:00:00 AM
1003146780 5 Longbine Abel 2/9/2015 12:00:00 AM
1001136448 1 Cerutti Abel 2/10/2015 12:00:00 AM
Upvotes: 0
Views: 342
Reputation: 478
you are adding line break after every column what you need to do is add it after every row like this
public string DisplayDataRow(DataView dataView)
{
string rows = null;
string lineBreak = "<br />";
foreach(DataRowView rowView in dataView)
{
for(int index = 0; index < dataView.Table.Rows.Count; index++)
rows += rowView.Row[index] + " ";
rows+=lineBreak;
}
return rows;
}
Upvotes: 1