更改复选框列表中选择列表项的背景颜色 [英] Change the background color of list item selected in check box list
本文介绍了更改复选框列表中选择列表项的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的网页使用的CheckBoxList如下:
I am using checkboxlist in my web page as follows:
<asp:CheckBoxList ID="chklstTelpas" runat="server" RepeatDirection="Horizontal"
AutoPostBack="True" Width="594px"
OnSelectedIndexChanged="chklstTelpas_SelectedIndexChanged">
<asp:ListItem Text="TELPAS Speaking" Value="1"></asp:ListItem>
<asp:ListItem Text="TELPAS Listening" Value="2"></asp:ListItem>
<asp:ListItem Text="TELPAS Reading" Value="3"></asp:ListItem>
<asp:ListItem Text="TELPAS Writing" Value="4"></asp:ListItem>
</asp:CheckBoxList>
现在,如果我检查列表项目,我想申请特定所选项目的背景颜色。如果我取消,我想的背景下保持了最初显示的相同的颜色,或者我想删除的背景颜色。
Now if I check a list item, I would like to apply some background color for that particular selected item. If i uncheck, I would like the background to remain the same color that was initially displayed, or I would like to remove the background color.
推荐答案
您可以做这样的事情。
for (int i = 0; i < chklstTelpas.Items.Count; i++)
{
if (chklstTelpas.Items[i].Selected)
{
chklstTelpas.Items[i].Attributes.Add("style", "background-color: red;");
}
else
{
chklstTelpas.Items[i].Attributes.Add("style", "background-color: white;");
}
}
这将让你几个颜色的选择。如果您使用的SelectedIndex它西港岛线只给你最低的索引。
This will allow you to color several of the choices. If you use the SelectedIndex it wil only give you the lowest index.
这篇关于更改复选框列表中选择列表项的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文