如何为RadioButtonList的每个重复列设置不同的背景色
本文关键字:设置 背景色 RadioButtonList | 更新日期: 2023-09-27 18:24:13
我设置了3个重复列,我想为每个重复列使用不同的背景色,如果你对如何实现这一点有任何想法,请分享。
下面是我的RadioButtonList
代码
<asp:RadioButtonList ID="rblTimeSlot" runat="server" RepeatColumns="3" RepeatLayout="Table" AutoPostBack="False" CellPadding="10" CellSpacing="2" Font-Bold="False"></asp:RadioButtonList>
项目列表正在另一个事件上从数据库加载。
提前谢谢。
使用CSS nth-child
(>=IE9):
#rblTimeSlot tr:nth-child(even)
{
background-color:aqua;
}
或者jquery:
$("#rblTimeSlot tr:even").css("background-color","aqua");
如果你想对列做同样的操作,可以使用这个稍微修改过的css:
#rblTimeSlot tr > td:nth-child(even)
{
background-color:aqua;
}
或者jquery:
$("#rblTimeSlot tr>td:even").css("background-color","aqua");
您可以在XX.aspx.cx文件中这样写代码:
string[] color = { "red", "yellow","blue" };
for (int i = 0; i < rblTimeSlot.Items.Count; i++)
{
int j = i % color.lenght;
rblTimeSlot.Items[i].Attributes.Add("style", "color: " + color[j]+ ";");
}