I have been searching through numerous sites and feel frustrated:
Within my
<asp:table id="questionsTable" runat="server">
, I am dynamically adding rows and columns. My goal is to assign a predefined Cssclass to these newly created rows and columns, but I have not been successful.
The code for setting up 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 am aware that I can achieve this with:
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");
This solution works, but it clutters the code-behind file.
I came across this alternative approach:
row.Attributes.Add("Class", "rowA");
// CSS - in StyleSheet.css
.rowA
{
width: 80%;
text-align: center;
background-color: #FCF6CF;
}
However, it does not seem to be working for me...
Interestingly, when I inspect the generated markup source, I see this:
</tr><tr Class="rowA">
The above snippet is copied from the rendered page, yet the Css rules are not applied. I have confirmed that the Css is correct because manual application works as expected.
EDIT
I would like to express my gratitude to all who contributed to this issue. Unfortunately, an error occurred which led to the deletion of the link to the external stylesheet. Credit goes to Sven for pointing that out. After a long day like today, even I can make beginner mistakes.
Thank you once again.
Best regards,
Aiden