?
Solved

accessing the class parameter of a HtmlTable

Posted on 2004-07-30
8
Medium Priority
?
315 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 750 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

Technology Partners: 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!

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month9 days, 6 hours left to enroll

764 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