473,395 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

DataTable to Html

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.

Although there are hundreds of examples available online, they all focus on
ASP or DataBinding with windows forms - neither of which I am interested in.
Of course, I can iterate through the rows of the DataTable and manually
create the HTML (which isn't too painful) but it seems that I'm missing
something important. I tried converting it to the System.Web.HtmlTable but
even that wouldn't spit out the HTML I'm looking for.

Any pointers?

Thanks, bob
Mar 14 '06 #1
2 12332
Bob Weiner wrote:
It seems to me that the easiest way to do it is to convert the DataTable
to HTML. Of course, I can iterate through the rows of the
DataTable and manually create the HTML
....which is probably what I'd do in your particular situation. :)
I tried converting it to the System.Web.HtmlTable but even that wouldn't
spit out the HTML I'm looking for.


There are two options I can see, if you want something cooler than a big fat
string.Format() line with embedded HTML:

1) You can create a System.Web.UI.WebControls.DataGrid, DataBind() it, and
call RenderControl() to get the HTML output (as described here:
http://aspnet.4guysfromrolla.com/articles/091102-1.aspx ). This is what you
said you didn't want to do -- but I suspect it is simpler than you thought
when you wrote that. Although you'd make use of a webcontrol, the use of
this method isn't limited to ASP.NET webpages.

2) You can write out the datatable as XML and apply XSL transform to get the
desired HTML output. System.Xml.Xsl namespace has everything you need to do
this. This method is very flexible and arguably elegant, but somewhat more
complicated than the webcontrol approach (and a lot more complicated than
the big fat string.Format()).
--
Chris Priede
Mar 14 '06 #2
Thanks!

I thought I was missing something huge but I guess not. I will try method
one for instructive purposes. The second method seems like overkill though
when I get around to playing with xml I may try it, too.

bob
"Chris Priede" <pr****@panix.com> wrote in message
news:eJ**************@TK2MSFTNGP10.phx.gbl...
Bob Weiner wrote:
It seems to me that the easiest way to do it is to convert the DataTable
to HTML. Of course, I can iterate through the rows of the
DataTable and manually create the HTML


...which is probably what I'd do in your particular situation. :)
I tried converting it to the System.Web.HtmlTable but even that wouldn't
spit out the HTML I'm looking for.


There are two options I can see, if you want something cooler than a big
fat string.Format() line with embedded HTML:

1) You can create a System.Web.UI.WebControls.DataGrid, DataBind() it, and
call RenderControl() to get the HTML output (as described here:
http://aspnet.4guysfromrolla.com/articles/091102-1.aspx ). This is what
you said you didn't want to do -- but I suspect it is simpler than you
thought when you wrote that. Although you'd make use of a webcontrol, the
use of this method isn't limited to ASP.NET webpages.

2) You can write out the datatable as XML and apply XSL transform to get
the desired HTML output. System.Xml.Xsl namespace has everything you need
to do this. This method is very flexible and arguably elegant, but
somewhat more complicated than the webcontrol approach (and a lot more
complicated than the big fat string.Format()).
--
Chris Priede

Mar 14 '06 #3

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

Similar topics

4
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...
2
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...
3
by: Dan V. | last post by:
How can I use real SQL on a DataTable? i.e. not array of rows using a filter... as in DataTable.Select. I read at : microsoft.public.dotnet.framework.adonet "As others have posted: There is no...
3
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...
12
by: Alphonse Giambrone | last post by:
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...
7
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...
6
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...
10
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...
4
by: Joseph Geretz | last post by:
I don't get it. A DataTable can't be returned, but a DataSet can. Yet a DataSet contains one or more DataTables. So obviously a DataTable must be serializable. So why not just let me return a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.