[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 829
  • Last Modified:

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

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
0
andichilds
Asked:
andichilds
1 Solution
 
REA_ANDREWCommented:
Table1.CssClass = "testing1"
0
 
Swapnil PipariaArchitectCommented:
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

Regards,
NetSwap
0
 
REA_ANDREWCommented:
you use cssclass with an asptable like the following markup shows

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

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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
andichildsAuthor Commented:
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?
0
 
skiltzCommented:
If you are using ASP 2.0 you could look at theme's and skins
0
 
andichildsAuthor Commented:
Thanks very much for your comments.

I changed my table to an asp:Table and all is working; thanks REA_ANDREW.
0
 
REA_ANDREWCommented:
Glad I could help
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now