Solved

accessing the class parameter of a HtmlTable

Posted on 2004-07-30
8
314 Views
Last Modified: 2008-03-04
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?
0
Comment
Question by:sethUSer420
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
8 Comments
 
LVL 12

Expert Comment

by:AGBrown
ID: 11677406
Can you not just use dividerCol1.CssClass?
0
 
LVL 12

Expert Comment

by:AGBrown
ID: 11677420
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
0
 

Author Comment

by:sethUSer420
ID: 11677447
'System.Web.UI.HtmlControls.HtmlTableCell' does not contain a definition for 'CssClass'
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:AGBrown
ID: 11677465
haha, I knew there would be a problem like that.

Andy
0
 

Author Comment

by:sethUSer420
ID: 11677488
haha

then dont waste my time with it
0
 
LVL 12

Expert Comment

by:AGBrown
ID: 11677610
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
0
 
LVL 12

Expert Comment

by:AGBrown
ID: 11677680
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");
      }
}
0
 
LVL 12

Accepted Solution

by:
AGBrown earned 250 total points
ID: 11678887
If you do this a lot, and you want more brevity in your code, you could always create a custom control inheriting a tablecell class. You could add your own myCssClass property to it, and then override the RenderAttrbutes method, adding the attributes at this stage from the properties that were set, and then calling the base RenderAttributes.

Might be more hassle than it is worth though. I suppose you could always use the WebControls (which have a cssclass property) instead of the HtmlControls, but there are probably advantages to using the HtmlControls in your situation which is why you haven't just gone for the WebControls in the first place.

Andy
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question