I have a dataset
DataSet ds = Access.Get(startdate, enddate);
I returns me about 70 rows.I need to build an html table based on this to provide printing option. Any suggestions on how to do this? Thanks
I have a dataset
DataSet ds = Access.Get(startdate, enddate);
I returns me about 70 rows.I need to build an html table based on this to provide printing option. Any suggestions on how to do this? Thanks
Pass DataSet table to ConvertDataSetTableToHTML. Ensure your dataset always have table with records before calling.
if (ds != null)
{
if (ds.Tables.Count >0 )
{
if (ds.Tables[0].Rows.Count > 0)
{
ConvertDataSetTableToHTML(ds.Tables[0]);
}
}
}
public static string ConvertDataSetTableToHTML(DataTable dt)
{
string html = "<table>";
//add header row
html += "<tr>";
for(int i=0;i<dt.Columns.Count;i++)
html+="<td>"+dt.Columns[i].ColumnName+"</td>";
html += "</tr>";
//add rows
for (int i = 0; i < dt.Rows.Count; i++)
{
html += "<tr>";
for (int j = 0; j< dt.Columns.Count; j++)
html += "<td>" + dt.Rows[i][j].ToString() + "</td>";
html += "</tr>";
}
html += "</table>";
return html;
}
I just used the code from here for your scenario.