Solved

accessing the class parameter of a HtmlTable

Posted on 2004-07-30
8
303 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
  • 6
  • 2
8 Comments
 
LVL 12

Expert Comment

by:AGBrown
Comment Utility
Can you not just use dividerCol1.CssClass?
0
 
LVL 12

Expert Comment

by:AGBrown
Comment Utility
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
Comment Utility
'System.Web.UI.HtmlControls.HtmlTableCell' does not contain a definition for 'CssClass'
0
 
LVL 12

Expert Comment

by:AGBrown
Comment Utility
haha, I knew there would be a problem like that.

Andy
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:sethUSer420
Comment Utility
haha

then dont waste my time with it
0
 
LVL 12

Expert Comment

by:AGBrown
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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 .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now