Z
Zdenko Rupcic
How to programatically add cssStyle property to HtmlTableCell (or any other control)? I need to create and populate HtmlTableCell at run-time (because some requirements need to be met for the cell to be displayed) and I can't use System.Web.UI.WebControls.TableCell instead because I'm placing the cell in a HtmlTable.
Code goes like this:
Dim newrow As New HtmlTableRow
Dim newcell As New HtmlTableCell
newcell.ColSpan = 4
newcell.Attributes.CssStyle.Value = "tablecell" 'defined inside css file
newcell.InnerHtml = "<a href=""new.aspx"">new</a>" 'link to display in a cell
newrow.Cells.Add(newcell)
tblMain.Rows.Add(newrow) 'tblMain is html table
This creates the cell correctly (including colspan attribute and link contained within), but will not assign cssStyle attribute to it. Page source shows this:
<tr>
<td colspan="4" style="tablecell"><a href="new.aspx">new</a></td>
</tr>
Obviously, there should be "class" attribute instead of "style".
Code goes like this:
Dim newrow As New HtmlTableRow
Dim newcell As New HtmlTableCell
newcell.ColSpan = 4
newcell.Attributes.CssStyle.Value = "tablecell" 'defined inside css file
newcell.InnerHtml = "<a href=""new.aspx"">new</a>" 'link to display in a cell
newrow.Cells.Add(newcell)
tblMain.Rows.Add(newrow) 'tblMain is html table
This creates the cell correctly (including colspan attribute and link contained within), but will not assign cssStyle attribute to it. Page source shows this:
<tr>
<td colspan="4" style="tablecell"><a href="new.aspx">new</a></td>
</tr>
Obviously, there should be "class" attribute instead of "style".