473,322 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

ListItem color change - RB

mg
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>

Nov 17 '05 #1
4 9563
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>

.

.

Nov 17 '05 #2
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[i];

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 theserver 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 asingle ListItem of a RadioButtonList when the associatedradiobutton 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>

.

.

.

Nov 17 '05 #3
mg
Alex,

That did the job. Thanks!

mg

P.S. I changed

RadioButtonList1_2_onclick; to RadioButtonList1_0_onclick;
-----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[i];

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 ontheserver 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 besideasingle ListItem of a RadioButtonList when theassociatedradiobutton 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>

.

.

.

.

Nov 17 '05 #4
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>

.

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Do | last post by:
Hi, In my listbox, I'd like to change the color of some listitems depending on user security. I tried wrapping the <font color=red></font> around my listitme's .text property, but the tags...
4
by: Shaul Feldman | last post by:
Hello, I have something really awkward at work - fighting with CheckBoxList... How can I define CSS for ListItem in CheckBoxList programmatically. I add CheckBoxList's Items on the fly, something...
2
by: Amelyan | last post by:
How can I assign an ID to dynamically generation ListItem that I add to dynamically generated CheckBoxList or RadioButtonList? I need to identify the specific ListItem later through Request.Form...
4
by: Hong Yip | last post by:
Hi Everyone, I have an array of checkboxlist. Everything works prefectly fine until I start working on the "presentation" view. I am not able to "insert" a checkbox item to a table cell. ...
3
by: Nathan Sokalski | last post by:
I want to change the background color, font attributes, etc. of the choices in my DropDownLists. When writing them using HTML SELECT and OPTION tags, I can do something like the following: ...
8
by: barry | last post by:
Have tried a number of things including space(n) in front of the string but when the DropDownList is shown the spaces have apparently been trimmed. Is this something that would have to be done in a...
5
by: Mark Rae | last post by:
Hi, Has the <asp:DropDownList> - <asp:ListItem> functionality changed in v2? In v1.1, the following works as expected: <asp:DropDownList ID="cmbStatus" Runat=server EnableViewState=False>...
4
by: Kevin Blount | last post by:
As mentioned before, I'm creating a multi-lingual page where the text of the page comes from a database. This page includes a registration form which asks for address information, including the...
5
by: ssmeshack | last post by:
Hi All, Im using VWD 2008 (c#), I have a question here. Im having a dropdownlist like this: <asp:DropDownList ID="ddlIssue" runat="server" AutoPostBack="True" ...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.