Link to home
Start Free TrialLog in
Avatar of sethUSer420
sethUSer420

asked on

accessing the class parameter of a HtmlTable

it's easy to manipulate the style param of a <td> within .net you just:

dividerCol1.Style.Clear();
dividerCol1.Style.Add("background-color","#CCCCCC");

or whatever

is there easy access to the css class param of a <td>? like <td class="backColor"> or do I have to go through the attributes property?
Avatar of AGBrown
AGBrown
Flag of United Kingdom of Great Britain and Northern Ireland image

Can you not just use dividerCol1.CssClass?
Sorry, that was not meant to be flippant. I have been setting class attributes of various objects (including <tr> and <td>) using the cssclass property, admittedly that was through a datagrid.

Andy
Avatar of sethUSer420
sethUSer420

ASKER

'System.Web.UI.HtmlControls.HtmlTableCell' does not contain a definition for 'CssClass'
haha, I knew there would be a problem like that.

Andy
haha

then dont waste my time with it
For an HtmlControl run at the server, use

Dim tblc As System.Web.UI.HtmlControls.HtmlTableCell
Dim tblr As System.Web.UI.HtmlControls.HtmlTableRow
For Each tblr In Me.Table1.Rows
    tblr.Attributes.Add("class", "Row Class")
    For Each tblc In tblr.Cells
        tblc.Attributes.Add("class", "Cell Class")
    Next
Next
or in c#, which your question was in

foreach (HtmlTableRow tblr in this.Table1.Rows)
{
      tblr.Attributes.Add("class", "row class");
      foreach (HtmlTableCell tblc in tblr.Cells)
      {
            tblc.Attributes.Add("class", "cell class");
      }
}
ASKER CERTIFIED SOLUTION
Avatar of AGBrown
AGBrown
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial