-----Original Message-----
mg,
I couldn't get anything to happen on the server-side
either, but managed to write some client-side script to
achieve the color change (and also modify any of the
radio buttons attributes too).
Assume your form is called "Form1" and your
radiolist "RadioButtonList1", and that you have 2
elements in the list.
First modify the <BODY> tag in your HTML to read <BODY
onload = 'assign_events();'>
then add the following javascript functions. This is
kind of clunky, and can be simplifed by writing out the
client scripts from server side page.RegisterClientScript
calls.
alex
function assign_events() {
document.all("RadioButtonList1_0").onclick =
RadioButtonList1_2_onclick;
document.all("RadioButtonList1_1").onclick =
RadioButtonList1_1_onclick;
}
function RadioButtonList1_0_onclick() {
dostuff(this);
}
function RadioButtonList1_1_onclick() {
dostuff(this);
}
function dostuff(item)
{
for (i=0;i<document.Form1.length;i++)
{
Obj = document.Form1.elements
;
if (Obj.type == 'radio')
{
Obj.nextSibling.style.color = "black";
}
}
item.nextSibling.style.color = "red";
}
-----Original Message-----
Alex,
I had no luck with the following code:
private void RadioButtonList1_SelectedIndexChanged( ...
{
foreach (ListItem li in RadioButtonList1.Items)
{
if (li.Selected==true)
{
li.Attributes["ForeColor"] = "red";
}
}
Any further thoughts?
mg
-----Original Message-----
Hi
You can access the ListItem.Attributes collection on the
server to change it's color.
eg
[C#]
foreach (ListItem li in RadioButtonList1.Items)
{
if (li.Selected)
li.Attributes["color"] = "red";
}
not tested, but should work.
alex
-----Original Message-----
How can I change the color of the display text beside a
single ListItem of a RadioButtonList when the associated
radiobutton is selected - hopefully using C# in the
codebehind of a WebForm?
<asp:RadioButtonList id="RadioButtonList1" ........ >
<asp:ListItem Value="Yes">Yes</asp:ListItem>
<asp:ListItem Value="No">No</asp:ListItem>
<asp:ListItem Value="Maybe">Maybe</asp:ListItem>
</asp:RadioButtonList>
.
.
.
.