Apply Css Style while creating Dynamic Table

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()));


Its actually pretty easy.

cel1.Style["CSSPROPERTY"] = "SomeValue"


cel1.Attributes.Add("class", "CSSCLASSNAME");

That oughtta do it

Try this

cel1.Attributes.Add("class", "className");


cel1.Style.Add("background-color", "red");

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.

Need Your Help

How can I have 2 leftBarButtonItems in iPhone app, and 1 be the default back button?

iphone xcode uinavigationcontroller uibarbuttonitem

I would like 2 leftBarButtonItems, but leave one of the items as the default back button for Navigation Controllers. I have set up:

Binary file reader byte[] to string conversion gone wrong?

java file file-io io

I'm trying to display whats in the file header which should be text (the rest of the file is binary) but when I print strtemp I get this: