Hi Alphonse,
I think if you want to get an Html table content from a given datatable,
generally we can consider either of the following means:
1. Since the System.Web.UI.WebControls.DataGrid can be created on the fly
and render out its html content.
We may manually create a DataGrid instance (set AutoGenerateColumns= true)
and bind the DataTable onto it , and call it's RenderControl method to
render into a HtmlTextWritter(created via a stringbuilder). After that , we
can get the datagrid's output html from the string builder. For example:
private void btnExport_Click(object sender, System.EventArgs e)
{
DataGrid dg = new DataGrid();
dg.AutoGenerateColumns = true;
dg.DataSource = GetDataTable();
dg.DataBind();
System.Text.StringBuilder sb = new System.Text.StringBuilder();
System.IO.StringWriter sw= new System.IO.StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
dg.RenderControl(htw);
divTable.InnerHtml = sb.ToString();
}
#sb.ToString() will return the htmltable content we want.
2. Put the DataTable into a DataSet and use the DataSet.GetXml method to
retreive the DataSet's xml representation. Then, use some custom xslt style
to transform the xml into html table content. This require us to provide an
xslt style sheet.
Hope these help. Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)