Can I dynamically change the css class of a table at runtime?

Posted on 2006-05-15
Last Modified: 2012-08-13
I have an ASP.NET web page (coded using VB.NET); on this page there is a table (tblMenu).

When the page loads I want to be able to specify the css class that the table should adopt but I can't figure out how to do it.

Can I have a line of code which sets the css class of the table when the page loads? The reason for this is I want the style of the table to change depending on a querystring value; for example:

Sub ChangeTableClass(strQueryStringValue)
  tblMenu.cssclass.value = strQueryStringValue

End Sub
Question by:andichilds
    LVL 20

    Expert Comment

    Table1.CssClass = "testing1"
    LVL 16

    Expert Comment

    by:Swapnil Piparia
    Hi andichilds,

        for that you need to add attribute runat="server" tag in table like <table id="tblMenu" runat="server">  and access it in your function like

    tblMenu.class = strQueryStringValue

    LVL 20

    Accepted Solution

    you use cssclass with an asptable like the following markup shows

            <asp:Table ID="Table1" runat="server">
            <asp:TableCell>This is a test</asp:TableCell>
            <asp:TableCell>This is another test</asp:TableCell>

    html tables then yes, that would be class, since cssclass was stated in the question, I assume you were using an asp:table and not html.

    Author Comment

    Thanks REA_ANDREW & netswap for you comments.

    I am using an HTML table and unfortunatly neither class or cssclass are part of System.Web.UI.HtmlControls.HtmlTable.

    Is the only way to get this to work to change my table to an asp:table?
    LVL 7

    Expert Comment

    If you are using ASP 2.0 you could look at theme's and skins

    Author Comment

    Thanks very much for your comments.

    I changed my table to an asp:Table and all is working; thanks REA_ANDREW.
    LVL 20

    Expert Comment

    Glad I could help

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my 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…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    761 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