Link to home
Start Free TrialLog in
Avatar of deleyd
deleydFlag for United States of America

asked on

C# writing data to HTML table

I am programming in C#. I have some data that I want to write to an HTML file as a table of 3 columns and an unknown number of rows.

Then I display that file in a web browser.

Currently this is all done by brute force. The C# code writes out the <HTML> tag and all the following header tags. It writes the <TABLE> tag. It loops through the data, writing each line of the table, adding appropriate <TR>...</TR> and <TD>...</TD> tags. It then closes the table with a </TABLE> tag, writes some footer information, and finally ends the file with a </HTML> tag.

There's got to be a better way.

This code works, but it's difficult to maintain.

I know PHP has a nice way of dealing with this, But I'm not using PHP, I'm using C#.

I've seen XSLT transformations that outputs nice HTML code, but my input isn't XML.

Is there a good way to deal with this in C#? Where I can create some sort of template that's easy to understand and maintain? A template that conveys the idea, "I want the output to be a HTML file which has a table of 3 columns"?
SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of deleyd

ASKER

Oh my thank you for pointing that out! I didn't know EE somehow added ASP.NET to the list.

I decided my real problem was separation of responsibilities. It's all intertwined the fetching to data and the formatting with HTML. The formatting is spread all over the program. I need to consolidate that so the formatting is in one place, and the fetching of data is a separate responsibility.

Thank you everyone for the help I greatly appreciate it, and sorry for the ASP.NET tag that somehow got in there.