Radiobutton inside repeater with dynamic ID and text

M

Matt Jensen

Am I right in saying that you can't have a Radiobutton web control inside a
repeater bound to a database datasource and (inline) dynamically set it's ID
and text properties from the repeaters rows?
This is the impression I've got after extensive searching and trial and
error, even thought I have to say I find it hard to believe?
Thanks
Matt
 
G

Guest

Hi Matt,

You may be able to dynamically set the radiobutton's id but i dont think it
would be very useful to you.

If you use the same id in the template, then by the INamingContainer
interface that the repeater implements, the ids will be unique on the client
side (if accessing them from script) and you can still find the control by
myRepeaterItem.FindControl("myradiobuttonid")

HTH jd
 
M

Matt Jensen

Ok, probably haven't explained it very well. Only wanted to do dynamic
labels to associate the HTML <label> tag with the correct radio button.

But ignoring the ID then for the moment (I actually also want to set the
'value' dynamically to, and which would have been better if I said that
instead of ID), how about dynamically setting the text?

E.g.
<asp:repeater ID="test" runat="server">
<itemtemplate>
<asp:RadioButton id="testid" Text="<%# Container.DataItem["myfield"]%>"
GroupName="testgroupname" runat="server"/>
</itemtemplate>
</asp:repeater>

?
Thanks
Matt
 
G

Guest

Hi Matt, I have just done a little experiment... you can't set the
radiobutton's id but definately can set the text.

The "name" html attribute gets mangled by INamingContainer and the Value
gets set to the "ID".

So you would still have to loop through the repeater and inspect each radio
button to work out if it is checked and to find the text ... HTH jd
 
G

Guest

If you use an html radiobutton you may have less trouble, you could set any
attributes through databinding (<%# %> style) but if you don't set
runat="server" you won't have any mangling from INamingContainer.. just a
thought...

Matt Jensen said:
Ok, probably haven't explained it very well. Only wanted to do dynamic
labels to associate the HTML <label> tag with the correct radio button.

But ignoring the ID then for the moment (I actually also want to set the
'value' dynamically to, and which would have been better if I said that
instead of ID), how about dynamically setting the text?

E.g.
<asp:repeater ID="test" runat="server">
<itemtemplate>
<asp:RadioButton id="testid" Text="<%# Container.DataItem["myfield"]%>"
GroupName="testgroupname" runat="server"/>
</itemtemplate>
</asp:repeater>

?
Thanks
Matt

london calling said:
Hi Matt,

You may be able to dynamically set the radiobutton's id but i dont think
it
would be very useful to you.

If you use the same id in the template, then by the INamingContainer
interface that the repeater implements, the ids will be unique on the
client
side (if accessing them from script) and you can still find the control by
myRepeaterItem.FindControl("myradiobuttonid")

HTH jd
 
M

Matt Jensen

Ok thanks jd, I'm probably going about it in the wrong way actually, still
thinking of it in terms of the classic ASP model of server/client
relationships, but currently I don't have time to worry about that....!
Looks like I'll just go with the basic HTML radio button element inside a
repeater (as you say)
Cheers
Matt
 

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,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top