Q:

C# Table created from database Formatting issue

I have some code that takes a few values from a database and then amends it to a html table via the following code.
if (!this.IsPostBack) {
            DataTable dt = Database.GetData();

            StringBuilder html = new StringBuilder();
            html.Append("<table border = '1'>");
            html.Append("<tr>");
            foreach(DataColumn column in dt.Columns){
                html.Append("<th>");
                html.Append(column.ColumnName);
                html.Append("</th>");
            }
            html.Append("</tr>");

            foreach (DataRow row in dt.Rows) {
                html.Append("<tr>");
                foreach (DataColumn column in dt.Columns) {
                    html.Append("<td>");
                    html.Append(row[column.ColumnName]);
                    html.Append("</td>");
                }
                html.Append("</tr>");
            }
            html.Append("</table>");

            Datatable.Controls.Add(new Literal { Text = html.ToString() });
        }

The problem being at run time the code is thrown out in one big line about 15 browser pages long instead of under the columns.
Any advice?

A:

Your code won't output as a table at the moment because you are missing a space between your table tag and your border attribute.
It should be <table border= '1'> not <tableborder='1'> if you want to render a table as at the moment it is not a valid table tag when it is interpreted by the browser.
Also your code should be output as 'raw' HTML if you want it to be rendered as HTML otherwise it will be treated as text, which is what it sounds like to me.

