Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add onclick to radiobutton within a repeater

Status
Not open for further replies.

sugarflux

Technical User
Aug 14, 2003
111
GB
Hi Guys

I've been struggling with this for days!

I have a radiobutton, label and a panel within a repeater and I'd simply like to add a javascript onclick to the radiobutton.

<rendering:RepeatTable ID="QuestionValues" runat="server" CssClass="myControl">
<asp:RadioButton ID="QuestionValue" runat="server" />
<asp:Label ID="QuestionValueLabel" runat="server" Text="Answ1" CssClass="QuestionValueLabel radio_false" />
<asp:panel ID="QuestionValueMedia" runat="server" />
</rendering:RepeatTable>

I've tried simply adding the onclick within the code above but it doesn't appear in the output. I've also tried

protected void Page_Load(object sender, EventArgs e)
{
QuestionValue.Attributes.Add("onclick", "mytest();");
}
but to no avail....

Any help would be greatly appreciated!

Thanks

~S~
 
The checkbos is within the repeater so this code
Code:
 QuestionValue.Attributes.Add("onclick", "mytest();");
will not work. You have to use the ItemDataBound event of the repater, then use the FindControl() method to get a reference to the checkbox. Once you do that, then you can add the onlick attribute.
 
Hi jBenson

Thanks for getting back to me...

Is there any chance you could show me how the ItemDataBound event would work? I'm new to .Net and feel like I'm stabbing in the dark a bit...

I tried QuestionValues.ItemDataBound but the repeater doesn't seem to have this method available...

I think that the repeater list has been customized (hence being called rendering:RepeatTable) - could this be effecting it?

Hope you don't mind helping me a bit more!

Thanks in advance

~S~
 
The ItemDataBound event is used like this, however as you say this is not a repeater control and is in fact a custom control.

If the custom control is inheriting the Repeater, then you will still have access to the event, if not you will have to have a look at what methods it does offer you for binding data.

Mark,

Darlington Web Design[tab]|[tab]Experts, Information, Ideas & Knowledge[tab]|[tab]ASP.NET Tips & Tricks
 
The methods available (to the RepeatTable) appear to be:

OnDataBinding
OnDisposed
OnInit
OnLoad
OnPreRender
OnSelectionChangedEvent
OnUnload

Can i use one of these?

Thanks - I really appreciate your help,

~S~
 
Thanks Mark

So I've tried adding

OnDataBinding="QuestionValues_DataBinding"

and in the c#:

protected void QuestionValues_DataBinding(Object Sender, RepeaterItemEventArgs e)
{

}

and i get the error:


Error 4 No overload for 'QuestionValues_DataBinding'

Sorry if I'm being dense - what am I doing wrong?

Thanks again

~S~
 
Ok , sorry I've figured out that this is because i was using RepeatItemEventArgs rather than just EventArgs.

So changing to this:

protected void QuestionValues_DataBinding(Object Sender, EventArgs e)
{

}

Where can i go from here to add my onclick events? Within the 'custom' repeater item there is a panel, label and a radiobutton..

so I'm guessing something along the lines of:

if(e.GetType()==RadioButton)
{

}

but not sure quite how to add the attribute. The 'e' variable gives me
Equals
GetHashCode
GetType
ToString

none of which seem to be what i need!

~S~
 
The event may not take the RepeaterItemEventArgs argument, or it may already be defined in your page. You'll need to consult the documentation for the custom control as this control isn't something that anyone here will have access to.

Mark,

Darlington Web Design[tab]|[tab]Experts, Information, Ideas & Knowledge[tab]|[tab]ASP.NET Tips & Tricks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top