I am facing a problem where I am unable to apply a .css class to my specific asp controls within a table -> tablerow -> tablecell.
However, I can directly add 'style' using reflection (not 'class').
For example:
In .aspx:
<asp:Table ID="_cellGrid" runat="server" CssClass="datagrid" Width="100%"></asp:Table>
In .cs:
TableRow dataTableRow = new TableRow() { };
_cellGrid.Rows.Add(dataTableRow);
TableCell dataRowCell = new TableCell() { };
dataTableRow.Cells.Add(dataRowCell);
Label label = new Label() { Text = "TEST" };
label.Attributes.Add("class", "custom");//THIS DOESN'T WORK
label.Attributes.Add("style", "background-color: Red; font-size:2.1em;");//THIS WORKS
dataRowCell.Controls.Add(label);
In .css:
.custom {
background-color: Red;
font-size:2.1em;
}
The .css file is correctly linked in my master page and I use it elsewhere on the same control (outside of the Table).
I do not want to use inline style .css throughout the table, and I require different styles for individual custom controls within table cells. Therefore, capturing the "table_row" css associated with asp:Table or other built-in elements is not possible (let me know if clarification is needed, I have a good example on this too).
If you can assist, please do so. It appears to be a simple task, yet here we are.