Creating HTML Tables with HtmlControls or WebControls
page 1 of 1
Published: 25 Oct 2003
Unedited - Community Contributed
Abstract
A comparison of the different methods of creating HTML tables in .NET.
by Damian Manifold
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 29544/ 19

Creating tables with HTMLControls or webControls

Creating tables with HTMLControls or webControls
by Damian Manifold

It must be said that at the time of writing this article most of the tables on this site are generated by building a string, pretty much the same way as you would have done it in classic ASP. But after creating controls for this site it suddenly dawned that there was a much better way to create tables in code 

Here are three techniques to create tables in code.

Source Code
OldTable.aspx The table page for the string technique
OldTable.aspx.vb The code behind for the string technique
Table.aspx The table page for the HTMLControl technique
Table.aspx.vb The code behind for the HTMLControl technique
NewTable.aspx The table page for the webControl technique
NewTable.aspx.vb The code behind for the webControl technique

"Oldtable" shows us how to create a table using a string, this is easily the most concise code, but is not clear at all. If you have used this technique is classic asp you will know how easy it is to forget closing tags. This technique also provides no formatting of the HTML and thus the generated page is a nightmare

"Table" show us how to create a table using HTMLControl objects. If you have ever created tables client side in JScript this will be familiar, as it is the same but for the declaration of the objects. All the attributes of the table are available through the object. This technique is much easier to read and takes away the generation of the tags, so missing out a closing tag is not a worry. You also benefit in that the HTML code produced is indented and easy to read.

"NewTable" show us how to create a table using webControl objects. This technique also gives you clarity in the code and the generated HTML. It also has typing on the attributes making it easier to set them correctly. You may notice when you run the examples that this is the only one where the row colors actually turned out as intended.

Examples
OldTable.aspx the string Technique in action
Table.aspx the HTMLControl Technique in action
NewTable.aspx the webControl Technique in action



User Comments

Title: creating table   
Name: jek
Date: 2008-10-30 5:30:19 AM
Comment:
sample is good..could you please send me an sample asp code creating a table and send it via email..my email add is c0yen@hotmail.com or ja3143@yahoo.com..tnx.
Title: My company blocks your code as malicious   
Name: bill
Date: 2008-02-12 6:20:29 PM
Comment:
um, the title says it all.
Title: sample source is broken   
Name: mike
Date: 2007-08-01 7:18:13 PM
Comment:
sample source is broken

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2017 ASPAlliance.com  |  Page Processed at 2017-10-20 1:21:15 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search