deleyd
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"?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.