Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更改c#if语句中html表格单元格的简单方法_C#_Html - Fatal编程技术网

更改c#if语句中html表格单元格的简单方法

更改c#if语句中html表格单元格的简单方法,c#,html,C#,Html,我有一个显示数据的html表格,我想根据if语句更改html表格单元格的颜色。我有runat=“server”和system.web.ui.htmlcontrols,但我找不到一种明确的方法来更改html表格单元格的颜色。我已经找了几个小时了。非常感谢您的帮助 if(Order != true) { //code for changing html table cell goes here } 尝试使用此方法,但html表未显示,TableRow或TableCell也未显示 Table

我有一个显示数据的html表格,我想根据if语句更改html表格单元格的颜色。我有runat=“server”和system.web.ui.htmlcontrols,但我找不到一种明确的方法来更改html表格单元格的颜色。我已经找了几个小时了。非常感谢您的帮助

if(Order != true)
{
    //code for changing html table cell goes here
}
尝试使用此方法,但html表未显示,TableRow或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;
下面是我在页面加载时添加数据的方法

public static List<LineData> getData()
{
    if(Order != true)
    {
        //code for changing html table cell goes here
    }
}
公共静态列表getData()
{
如果(顺序!=true)
{
//更改html表格单元格的代码如下
}
}
前端工作台启动

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

您必须设置表的Id才能在服务器端看到它

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


另外,如果已经定义了一个表,那么只需向其中添加行,不需要在服务器端定义另一个。

请同时显示前端代码和服务器端代码中更相关的部分。@Bobby5193抱歉,缺乏相关知识,但是前端和服务器端还需要什么来进行相关的操作?好的,定义表的部分,以及包含“if”的处理程序的位置是triggered@Bobby5193你回来了,你要把桌子放在哪里?您应该将它添加到运行在='server'上的html中的现有元素中