Reputation: 1333
Here is my problem:
When I create my table in C#, I would like to add different CSS style to each cell.
while (DR.Read()) {
TableRow linha1 = new TableRow();
cel1 = new TableCell();
cel2 = new TableCell();
cel3 = new TableCell();
cel4 = new TableCell();
cel1.Controls.Add(new LiteralControl(DR.GetValue(0).ToString()));
cel2.Controls.Add(new LiteralControl(DR.GetValue(1).ToString()));
cel3.Controls.Add(new LiteralControl(DR.GetValue(2).ToString()));
cel4.Controls.Add(new LiteralControl(DR.GetValue(3).ToString()));
linha1.Controls.Add(cel1);
linha1.Controls.Add(cel2);
linha1.Controls.Add(cel3);
linha1.Controls.Add(cel4);
Tab_artigos_all.Controls.Add(linha1);
}
Upvotes: 3
Views: 21806
Reputation: 23
I like the answers above, for sure. But you can also use the format of
cel1.Style(HtmlTextWriterStyle.FontSize) = 9
for example. Autocomplete drop-downs will obviously give you a list of possible values to use along with HtmlTextWriterStyle if you're in Visual Studio.
Upvotes: 1
Reputation: 477
Its actually pretty easy.
cel1.Style["CSSPROPERTY"] = "SomeValue"
or
cel1.Attributes.Add("class", "CSSCLASSNAME");
That oughtta do it
Upvotes: 9
Reputation: 148110
Try this
cel1.Attributes.Add("class", "className");
or
cel1.Style.Add("background-color", "red");
Upvotes: 5