Site Search:
Sign in | Join | Help
4Penny.net

ASP.NET

Notes, Tricks and Tips on ASP.NET Coding

Adding lines to an HTML Table in code (VB.NET)

Here's a useful tip for adding lines to an html table in code. Normally I'd define and populate a grid, but sometimes that's overkill 

 

 'declare the row
Dim tr As New HtmlTableRow


'declare the new cells
Dim td1 As New HtmlTableCell
Dim td2 As New HtmlTableCell


'set the content
td1.InnerHtml = "something"
td2.InnerHtml = "something else"


'set the ID property. This allows you to attach a CSS class to the cell
td1.ID = "report_cell"
td2.ID = "report_cell_title"


'another way to set a style
td1.Style.Add("width", "50px")


'add the cells to the row
tr.Cells.Add(td1)
tr.Cells.Add(td2)


'add the row to the table. This table is not declared in the code behind, it is a reference to a table in the 
'.aspx page declared like this:
'<table id="tblReport" runat="server"></table>
tblReport.Rows.Add(tr)

Comments

No Comments

About Steve Gray

Steve is a seasoned (translate: old) developer in VB and ASP.NET. He spends most of his time in Dynamics GP, writing custom mods for consulting firms. Crystal reports, eConnect, VS Tools for Dynamics... anything that comes along.