Solved

accessing the class parameter of a HtmlTable

Posted on 2004-07-30
8
307 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
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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 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