62,266
社区成员
发帖
与我相关
我的任务
分享List<string> ItemText = new List<string>();
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
RadioButtonList rbl = sender as RadioButtonList;
//string str= r.Items[0].Text;
foreach (ListItem item in r.Items)//我想记录下来每个控件的初始ListItem的Text;但是这样很明显不对
{
ItemText.Add(item.Text);
}
for (int i = 0; i < rbl.Items.Count; i++)
{
if (rbl.Items[i].Selected)
{
rbl.Items[i].Text = "<font style=\"color:Red\">" + rbl.Items[i].Text + "</font>";//换背景色
}
else//如果不是选中项就给他重新绑定初始数据
{
for (int j = 0; j < ItemText.Count; j++)
{
if (i==j)
{
rbl.Items[i].Text = ItemText[j];
}
}
}
}
} protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
RadioButtonList rbl = sender as RadioButtonList;
foreach (ListItem item in rbl.Items)
{
if (item.Selected)
{
item.Attributes.Add("style","background-color: red;");
}
}
} [Quote=引用 4 楼 的回复:]