Producing clean HTML tables in WebForms (.ASPX) pages
Posted: (EET/GMT+2)
Sometimes when working with pure JavaScript based web components or libraries, your HTML code needs to be as clean as possible. For new projects, I'm mainly working with ASP.NET MVC, but legacy applications I'm maintaining tend to be based on WebForms or .ASPX pages.
Recently, I had the need to produce a clean HTML table in an WebForms application. The table had to have "colgroup", "thead" and "tbody" elements; all of these are difficult to control with a GridView, for instance. Since I wanted to quickly solve the issue, I got back to the ol' and good Repeater component, which has been available since .NET 1.1 in 2003. That component solved the requirements nicely, so problem was solved.
I've noticed that the more HTML5 goodies get implemented, the better it's to "get back to basics" in WebForms applications, too. In ASP.NET MVC applications this isn't an issue because it naturally gives full control of the HTML output to the developer. Remember, there are no web controls in MVC applications.