Kpt.Khaos
Kpt.Khaos

Reputation: 693

Simple way to change html table cell in c# if statement

I have a html table that I am display my data in and I want to change the html table cells colors based on my if statement. I have runat="server" and I have system.web.ui.htmlcontrols but I can't find a clear way of how to change a html tables cell colors. I have been looking/trying for a couple hours. Any help with this is greatly appreciated!

if(Order != true)
{
    //code for changing html table cell goes here
}

Attempted this method but html table did not show nor did the TableRow or TableCell

TableRow row = new TableRow();
TableCell cell = new TableCell();
cell.Text = "Testing";
cell.BackColor = System.Drawing.Color.Red;
row.Cells.Add(cell);
table.Rows.Add(row);

table.Rows[0].Cells[0].BackColor = System.Drawing.Color.Pink;

Here is my method on page load excluded adding data

public static List<LineData> getData()
{
    if(Order != true)
    {
        //code for changing html table cell goes here
    }
}

Front end table start

<table style="border: medium solid #FFFFFF; 
              background-color: #000000; 
              border-color:White; 
              position: fixed;"
       border="2" 
       width="100%" 
       title="myTable" 
       runat="server" >

Upvotes: 0

Views: 1727

Answers (1)

Bobby5193
Bobby5193

Reputation: 1625

You have to set the Id of the table in order to see it on the server side.

<table style="border: medium solid #FFFFFF; 
              background-color: #000000; 
              border-color:White; 
              position: fixed;"
       border="2" 
       width="100%" 
       id="myTable" 
       runat="server" >

Also, If you already have a table defined, then you can just add rows to it, there is no need to define another one on the server-side.

Upvotes: 2

Related Questions