How to add CSS class to asp.net from code behind [closed]


Tags: c#,asp.net,html,css

Problem :

this is really frustrating and have search a dozen sites:

I have a <asp:table id="questionsTable" runat="server"> to which i dynamically add rows and columns. I am trying to add a predefined Cssclass to these newly created rows and columns, but to no avail.

The setup code for the rows and columns:

TableRow row = new TableRow();
TableCell cell1 = new TableCell();
TableCell cell2 = new TableCell();
TableCell cell3 = new TableCell();
TableCell cell4 = new TableCell();
TableCell cell5 = new TableCell();

I know i can do this:

row.Style.Add("width", "80%");
row.Style.Add("text-align", "left");

cell1.Style.Add("width", "10px");
cell2.Style.Add("width", "auto");
cell3.Style.Add("width", "75px");
cell4.Style.Add("width", "75px");
cell5.Style.Add("width", "75px");

And it works... but it makes the code-behind file messy.

So i've seen this:

row.Attributes.Add("Class", "rowA");

//CSS - in StyleSheet.css
.rowA
{
    width:80%;
    text-align:center;
    background-color:#FCF6CF;
}

But it does not seem to be working for me....

But strangely enough if i look at the markup source generated i get this

    </tr><tr Class="rowA">

The above is copied from the rendered page - yet the Css is not being applied... I know the css is correct because if i add it manually it applies it correctly.

EDIT

To all who assisted in this thank you very much. Unfortunately something went wrong and the link to the external stylesheet got deleted. Kudos to Sven for thinking of that. After a long day such as today i to can make beginner mistakes.

thank you once again

Kind regards

Aiden



Solution :

When the generated html output of the row has the class, then there is the css file not linked in the html file, or you have a typo in the class name.


    CSS Howto..

    Web Extension : How do I use “browser_style = true”?

    How to divide in 4 equal parts a li menu

    How to prevent inherit for H1?

    HTML: How to change the width of input field based on container size

    How to show scrollbar when the inner content is aligned to bottom?

    how to center two div in xs

    How do I vertically center text and have the dark blue bar go across the entire screen

    In CSS, how to grow the button + button image when the button is focused?

    How does Mozilla create this animated effect?

    How to layer a
    element ontop of a other elements

    How to solve CSS -webkit-appearance issue

    how to middle vertical-align using bootstrap input-group

    How to rotate an image with CSS style transform by an variable of degree?

    How to style the parent element when hovering a child element?

    How do I display the first image from each div with .className?

    How do horizontally align text next to an image with CSS

    How to get rid of space between buttons and content/paragraph? (CSS)

    Jquery, CSS - How to set element as first in list

    Show div at mouse click position, accounting for scrolling

    How to set the select to have the width of the selected option

    Show child elements into parent by changing its class through jquery

    How to customize the EditorFor CSS with razor

    How to make rounded tabs with css? [closed]

    How do i use floats for images while using
    so that
    still shows under image?

    How to make function NOT highlight last row in table?

    How to scroll horizontally when there are many columns (or a very long row)?

    How to create a 3 columns fluid fixed fluid layout?

    How do CSS grid systems save time when implementing designs that aren’t grid-based?

    How to achieve a silk-screen effect (a dotted shadowy effect) on an image with javascript/jquery?

    how to override font-color dynamically with css color property