如何在运行 asp.net 页面时以编程方式设置表格背景?

The*_*esa 3 c# asp.net background-color

我有一个 aspx 页面,默认背景色为一种。I need to be able to change it programmatically when a certain option of a radio button is selected. 我尝试设置表的 ID 字段,但似乎无法在我的 C# 代码隐藏文件中访问它。

我原来的表是:

<table id="tblSheet" runat="server" style="border-color: #FF9900; border-style: solid; 
border-width:  thin; width:100%; background-color: #99ccff;" cellspacing="4" 
cellpadding="1">
Run Code Online (Sandbox Code Playgroud)

不过,我在智能感知中没有看到 id。

编辑:
现在我可以在后面的代码中看到我的表格,我正在尝试实际更改背景颜色。这是我的单选按钮列表的代码:

<asp:RadioButtonList ID="rdoStatus" runat="server" AutoPostBack="true"
RepeatDirection="Horizontal" Visible="true"   
OnSelectedIndexChanged="rdoStatus_OnSelectionChanged">
<asp:ListItem Value="181001" Text="Open"/>
<asp:ListItem Value="181002" Text="Closed" />
<asp:ListItem Value="181003" Text="Pending" />
</asp:RadioButtonList>
Run Code Online (Sandbox Code Playgroud)

我遇到了在事件处理程序中设置的断点,但回发时背景颜色没有改变。如果选择的项目是待定的,那么我想将背景颜色更改为不同的颜色。如果他们将单选按钮更改为打开或关闭,那么我想确保背景颜色是默认值。

编辑 2:
我的事件处理程序中的代码非常简单:

if (rdoStatus.SelectedValue == "181003")
{
  tblSheet.BgColor = "#ff9a9a";
}
else
{
  tblSheet.BgColor = "#99ccff";
}
Run Code Online (Sandbox Code Playgroud)

Nak*_*nch 5

放置runat="server"在表格标签中

完成后,您将能够以编程方式访问该表。

要直接更改背景颜色,请尝试:

if (rdoStatus.SelectedValue == "181003")
    {
      tblSheet.Style.Add("background-color", "#ff9a9a");
    }
    else
    {
      tblSheet.Style.Add("background-color", "#99ccff");
    }
Run Code Online (Sandbox Code Playgroud)

如果您可以使用样式表,请尝试以下操作:

if (rdoStatus.SelectedValue == "181003")
{
  tblSheet.CssClass = "default_color"
}
else
{
  tblSheet.CssClass = "other color"
}
Run Code Online (Sandbox Code Playgroud)