I am using a StringBuilder to create a HTML file from my DataTable. The file is created but when I open it in the webbrowser I have to scroll all the way down to see the table. In other words there is a big blank page first with nothing at all.
Public Function ConvertToHtmlFile(ByVal myTable As DataTable) As String
Dim myBuilder As New StringBuilder
If myTable Is Nothing Then
Throw New System.ArgumentNullException("myTable")
Else
'Open tags and write the top portion.
myBuilder.Append("<html xmlns='http://www.w3.org/1999/xhtml'>")
myBuilder.Append("<head>")
myBuilder.Append("<title>")
myBuilder.Append("Page-")
myBuilder.Append("CLAS Archive")
myBuilder.Append("</title>")
myBuilder.Append("</head>")
myBuilder.Append("<body>")
myBuilder.Append("<br /><table border='1px' cellpadding='5' cellspacing='0' ")
myBuilder.Append("style='border: solid 1px Silver; font-size: x-small;'>")
myBuilder.Append("<br /><tr align='left' valign='top'>")
For Each myColumn As DataColumn In myTable.Columns
myBuilder.Append("<br /><td align='left' valign='top' style='border: solid 1px blue;'>")
myBuilder.Append(myColumn.ColumnName)
myBuilder.Append("</td><p>")
Next
myBuilder.Append("</tr><p>")
'Add the data rows.
For Each myRow As DataRow In myTable.Rows
myBuilder.Append("<br /><tr align='left' valign='top'>")
For Each myColumn As DataColumn In myTable.Columns
myBuilder.Append("<br /><td align='left' valign='top' style='border: solid 1px blue;'>")
myBuilder.Append(myRow(myColumn.ColumnName).ToString())
myBuilder.Append("</td><p>")
Next
Next
myBuilder.Append("</tr><p>")
End If
'Close tags.
myBuilder.Append("</table><p>")
myBuilder.Append("</body>")
myBuilder.Append("</html>")
'Get the string for return. myHtmlFile = myBuilder.ToString();
Dim myHtmlFile As String = myBuilder.ToString()
Return myHtmlFile
End Function
StringBuilderdirectly or show us what that is? Telling us that you have an issue with some data but not showing us that data seems to be rather counter-intuitive, don't you think? Regardless, what are all those<p>and<br />tags doing in there? Why would you have paragraphs and line breaks between rows and cells?