473,699 Members | 2,838 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datatable to HTML

Is there a simple way to convert the contents of a datatable to an HTML
table.
I have a dataset containing multiple datatables that I need to be able to
insert all the data into an html email.
I could loop through the rows of each datatable, but thought there might be
a simpler method.

TIA
--

Alphonse Giambrone
Email: a-giam at customdatasolut ions dot us

Nov 18 '05
12 2896
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.W ebControls.Data Grid can be created on the fly
and render out its html content.
We may manually create a DataGrid instance (set AutoGenerateCol umns= 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.EventArg s e)
{
DataGrid dg = new DataGrid();
dg.AutoGenerate Columns = true;

dg.DataSource = GetDataTable();
dg.DataBind();

System.Text.Str ingBuilder sb = new System.Text.Str ingBuilder();
System.IO.Strin gWriter sw= new System.IO.Strin gWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter( sw);

dg.RenderContro l(htw);

divTable.InnerH tml = 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.)
Nov 18 '05 #11
Thanks Steven,

I have already written the routine to loop through the datatables to get
what I need, but I will certainly try what you propose as it seems like it
might have more flexibility for future use.

--

Alphonse Giambrone
Email: a-giam at customdatasolut ions dot us
"Steven Cheng[MSFT]" <v-******@online.m icrosoft.com> wrote in message
news:XW******** ********@cpmsft ngxa10.phx.gbl. ..
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.W ebControls.Data Grid can be created on the fly
and render out its html content.
We may manually create a DataGrid instance (set AutoGenerateCol umns= 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.EventArg s e)
{
DataGrid dg = new DataGrid();
dg.AutoGenerate Columns = true;

dg.DataSource = GetDataTable();
dg.DataBind();

System.Text.Str ingBuilder sb = new System.Text.Str ingBuilder();
System.IO.Strin gWriter sw= new System.IO.Strin gWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter( sw);

dg.RenderContro l(htw);

divTable.InnerH tml = 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.)

Nov 18 '05 #12
Thanks for your followup Alphonse,

If you have any further questions later, please feel free to post here.
Good luck!
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.)

Nov 18 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
6835
by: js | last post by:
I'm just wondering if anyone have come across a code that reads an html file,search for <table> tag and convert its contents into a datatable and save it into a dataset.If there are few html tables,then each will be converted into a datatable and added into the same dataset. thanks.
2
14896
by: Ran | last post by:
hi all, I have been trying to use HTML table inside a h:dataTable (JSF component) and without any luck. anyone could give some hints on nesting standard HTML with JSF component ? OR How to make a horizontal dataTable without customizing JSF component ? (column names on the left, associated values on the right)
3
10088
by: DapperDanH | last post by:
I want to make a class that basically looks at the clipboard, and for the standard types of clipboard objects (csv,text, etc), create a DataTable from it. Not all formats will be supported but as many as possible. The idea is to be able to convert the clipboard into a DataTable, and then pass the DataTable to another class to do some work on it. I have started the class here: http://www.theoren.com/DanH/ClipBoardDataTable.cs Right...
3
1750
by: John Baker | last post by:
Hi:7 Newby here to ASP, and using the ASP.NET Web Matrix development tool. While that tool looks great for a Newby, I have run into a snag. I have an HTML Text Box which I have named HireInput, and a table (Access Table in fact) that has on it a field called HIREID. I wish to select records where the two match! It sounds simple, but I am having trouble setting up the text box name so that it is recognized in the query. Can someone...
7
1658
by: Raymond Lewallen | last post by:
Which would be the proper way or the reason for using any of the following or combinations of the following? These are the 3 ways I've figured I can do what I want to do, I just don't know which would be best: #1 ' Everything is create upon instantiation. Once completed, datatable can be obtained from the property. Public Class A Private dt as DataTable
6
16125
by: Dennis | last post by:
I have set a DataTable and one of the columns I set "AutoIncrement" to True. I then populate the Table by setting the columns to values then add the row to the table. I inadverently set the AutoIncrement Columns to different values but didn't get any errors. Should I be able to set the value of an AutoIncrement Column? I would have thought it couldn't be done as the column value was set when a row was added. -- Dennis in Houston
10
4945
by: JohnR | last post by:
I have a datatable as the datasource to a datagrid. The datagrid has a datagridtablestyle defined. I use the datagridtablestyle to change the order of the columns (so they can be different than the column order of the datatable). I also allow the user to click on a column header to sort the datagrid by that column. I need to identify the row and column in the datatable when the user clicks on a cell in the datagrid. Using the...
2
12344
by: Bob Weiner | last post by:
This is most likely a trivial question but I'm having a hard time finding an example. I am writing a script using C# 1.1 which iterates over AD accounts and builds a DataTable for those with passwords expiring within various periods of time. After sending mail to the users, I want to send a report to the help desk with a table of users included. It seems to me that the easiest way to do it is to convert the DataTable to HTML. ...
3
6679
by: vj83 | last post by:
Hi, I have a C#.net application in which i have read the datas from excel sheet and displayed in a datagrid in my Aspx form. The code is here private void Button2_Click(object sender, System.EventArgs e) { try
0
8685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8880
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6532
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2342
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.