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
Your class
attribute should be lowercase (XHTML):
row.Attributes.Add("class", "rowA");
Also make sure your including the CSS file in the page your rendering your table.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With