how to create an html table from server side in asp.net 2.0

I have a web page and in that i want to display all the records from a table in a tabular form on the web page and i donot want to use datagrid control

but i donot want to write any server side coding on the html part.
so how can i create a html table from the server side and them add it to the html part at runtime.
ziorrinfotechAsked:
Who is Participating?
 
Chirag1211Connect With a Mentor Commented:
You can create object of HtmlTable in your server side code. And on the aspx page you can place a asp:panel object. So that on server-side code when you have prepared the HTMLTable you can directly write aspPanelObject.Controls.Add(HTMLTableObject). This will render your HTML Table on your aspx page at runtime.

For more Information see the link below:
http://samples.gotdotnet.com/quickstart/util/srcview.aspx?path=/quickstart/aspplus/samples/webforms/ctrlref/htmlctrl/HtmlTable/HtmlTable1.src

Regards,

Chirag Patel
0
 
zeroxpConnect With a Mentor Commented:
you can construct your table on the server side with the System.Web.UI.WebControls.Table. just add rows and cells to it. here is an example you can get a bit idea from it. after you table have all the rows and cells, you can append that to a location on the form. if you data is in a datatable, you can use GridView or DataGrid to display that in a table. here is a good article on using grid http://www.developer.com/net/asp/article.php/2210191

// example in C#
         Table tbl = new Table();
         TableRow row;
         TableCell cell;
         TextBox txt;
         cell = new TableCell();
         cell.Text = "Name:";
         row = new TableRow();
         row.Cells.Add(cell);
         txt = new TextBox();
         txt.Text = "Robot";
         cell = new TableCell();
         cell.Controls.Add(txt);
         row.Cells.Add(cell);
         tbl.Rows.Add(row);

         cell = new TableCell();
         cell.Text = "Company Name:";
         row = new TableRow();
         row.Cells.Add(cell);
         txt = new TextBox();
         txt.Text = "The Machine Company";
         cell = new TableCell();
         cell.Controls.Add(txt);
         row.Cells.Add(cell);
         tbl.Rows.Add(row);
         tbl.GridLines = GridLines.Both;
         tbl.CellPadding = 0;
         tbl.CellSpacing = 0;
         tbl.Width = Unit.Percentage(100);
         Panel1.Controls.Add(tbl);
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.