Public Shared Function ConvertDataSetToHtmlTable(ByVal targetDataSet As DataSet, ByVal tableID As String) As String
Dim targetTable As New DataTable
targetTable = targetDataSet.Tables(0)
Dim myHtmlFile As String = ""
If targetTable Is Nothing Then
Throw New System.ArgumentNullException("targetTable")
'Continue.
Else
End If
'Get a worker object.
Dim myBuilder As New StringBuilder()
'Open tags and write the top portion.
myBuilder.Append("<table id='" & tableID & "' border='1px' cellpadding='5' cellspacing='0' ")
myBuilder.Append("style='border: solid 1px Silver; font-size: x-small;'>")
'Add the headings row.
myBuilder.Append("<tr align='left' valign='top'>")
For Each myColumn As DataColumn In targetTable.Columns
myBuilder.Append("<td align='left' valign='top'>")
myBuilder.Append(myColumn.ColumnName)
myBuilder.Append("</td>")
Next
myBuilder.Append("</tr>")
'Add the data rows.
For Each myRow As DataRow In targetTable.Rows
myBuilder.Append("<tr align='left' valign='top'>")
For Each myColumn As DataColumn In targetTable.Columns
myBuilder.Append("<td align='left' valign='top'>")
myBuilder.Append(myRow(myColumn.ColumnName).ToString())
myBuilder.Append("</td>")
Next
myBuilder.Append("</tr>")
Next
'Close tags.
myBuilder.Append("</table>")
'Get the string for return.
myHtmlFile = myBuilder.ToString()
Return myHtmlFile
End Function
Dim targetTable As New DataTable
targetTable = targetDataSet.Tables(0)
Dim myHtmlFile As String = ""
If targetTable Is Nothing Then
Throw New System.ArgumentNullException("targetTable")
'Continue.
Else
End If
'Get a worker object.
Dim myBuilder As New StringBuilder()
'Open tags and write the top portion.
myBuilder.Append("<table id='" & tableID & "' border='1px' cellpadding='5' cellspacing='0' ")
myBuilder.Append("style='border: solid 1px Silver; font-size: x-small;'>")
'Add the headings row.
myBuilder.Append("<tr align='left' valign='top'>")
For Each myColumn As DataColumn In targetTable.Columns
myBuilder.Append("<td align='left' valign='top'>")
myBuilder.Append(myColumn.ColumnName)
myBuilder.Append("</td>")
Next
myBuilder.Append("</tr>")
'Add the data rows.
For Each myRow As DataRow In targetTable.Rows
myBuilder.Append("<tr align='left' valign='top'>")
For Each myColumn As DataColumn In targetTable.Columns
myBuilder.Append("<td align='left' valign='top'>")
myBuilder.Append(myRow(myColumn.ColumnName).ToString())
myBuilder.Append("</td>")
Next
myBuilder.Append("</tr>")
Next
'Close tags.
myBuilder.Append("</table>")
'Get the string for return.
myHtmlFile = myBuilder.ToString()
Return myHtmlFile
End Function
Comments
Post a Comment