Radiobutton inside repeater with dynamic ID and text

  • Thread starter Thread starter Matt Jensen
  • Start date Start date
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
 
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
 
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
 
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
 
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
 
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
 
Back
Top