Add onclick javascript code to each radio button in a RadioButtonList control

R

Ryan Taylor

Hello.

I am having another issue. I need to execute some JavaScript whenever a
radio button is clicked. I am currently using a RadioButtonList control to
generate the radio buttons because of its excellent ability to be bound to a
datasource. No matter what I do though, I am not able to add an onclick
event to the individual radio buttons in the page. How might I go about
this? Currently I have

private void Questions_OnItemDataBound(object sender, RepeaterItemEventArgs
e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
RadioButtonList rbl = (RadioButtonList)
e.Item.FindControl("AnswerOptions");
rbl.DataTextField="fullOptionDescription";
rbl.DataValueField="answerOptionId";
rbl.DataSource = ((DataRowView)
e.Item.DataItem).CreateChildView("questionId");
rbl.DataBind();

foreach(ListItem li in rbl.Items)
li.Attributes.Add("OnClick", "needToConfirm = true;");
}
}

I've tried other variants as well with no success.

Thanks in advance.
Ryan Taylor
 
Joined
Sep 1, 2006
Messages
1
Reaction score
0
Did you solve the problem? I have the same task for CheckBoxList... and still did not find any decision.

Thank you
 
Joined
Mar 20, 2008
Messages
1
Reaction score
0
protected void radio_OnDataBound(object sender, EventArgs e)
{
RadioButtonList rbl = (RadioButtonList)sender;
foreach (ListItem li in rbl.Items)
{
string s = "javascript.."
li.Attributes.Add("onclick", s);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top