thefrozencoder

Programming and Technology blog

Converting a DataTable to a Html table

Introduction

This post is another common question I see on the ASP.NET forums "How to convert a DataTable to a Html table".  The code uses simple looping through the DataTable’s columns and rows/columns to pull the column names and the row data out.  I use the HtmlTable, HtmlTableRow and HtmlTableCell objects to actually build the table on the fly.  I find this much easier than using a StringBuilder to create the Html.

The code samples in this post can be downloaded using the link at the bottom and were created using Visual Studio 2010.  There are samples for both C# and Visual Basic.NET in the download file as well.

DataTableToHtml.zip (24 kb)

Comments are closed