【发布时间】:2018-09-26 14:25:50
【问题描述】:
I am using a radio RadioButtonList in asp net to create 2 radio button that when selected are supposed to change color the first one being green and the second one red but i am not able to make the change said color
Tldr:更改为列表项 1 内的列表项绿色的小圆圈,更改为列表项 2 的小圆圈变为红色。
同样由于某种原因,它在 RadioButtonList1.Items 中无法识别我的 radiobuttonlist1
这是我的html代码
<asp:RadioButtonList CssClass="listitemcss" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged" ID="RadioButtonList1" RepeatDirection="Horizontal" runat="server">
<asp:ListItem >
<p style="color:transparent;"> s2</p>
</asp:ListItem>
<asp:ListItem Selected="True">
<p style="color:transparent;">2</p>
</asp:ListItem>
</asp:RadioButtonList>
这是我的 c#
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (RadioButtonList1.Items[0].Selected)
{
RadioButtonList1.Items[0].Attributes.Add("style", "background-color: green;");
}
if (RadioButtonList1.Items[1].Selected)
{
RadioButtonList1.Items[1].Attributes.Add("style", "background-color: red;");
}
}
【问题讨论】:
标签: c# asp.net visual-studio visual-studio-2017