Reputation: 859
I have a HTML radio button inside a repeater. I'm facing two problems:
When I'm binding Value from code behind (using datatable in code behind) it is throwing error server tag not found.
How to get the selected value in code behind
My code till now is this.
asp:Repeater runat="server" ID="rptr1">
<HeaderTemplate></HeaderTemplate>
<ItemTemplate>
<tr> <td>
<span><input type="radio" runat="server" name="acd" class="radio" id="radio1" value='<%# DataBinder.Eval(Container.DataItem, "valuinfm")%>'/></td><td> <label for="radio"><%# DataBinder.Eval(Container.DataItem, "txtinfm")%></label></span></td>
<br />
</tr>
</ItemTemplate>
<FooterTemplate></FooterTemplate>
</asp:Repeater>
I used this approach because there was some bug in using ASP.NET radio button with repeater. I don't want to use JavaScript.
Basically I want to redirect to other page by having querystring which is "value" of radio button.
Edited: // I have corrected it to single outer quotes now there is no error (Thanks to Brian).
Values in radio button are different but still I can click both and also how I can detect which radio button is selected:
Upvotes: 0
Views: 4348
Reputation: 3214
The problem is because the name attribute of the generated radio buttons gets a UniqueId appended to it. This is .NET trying to be helpful but in this case it causes problems as the browser groups radio buttons where the name attribute is the same. One possible solution is to create your own radio button web control which doesn't override the name attribute as discussed in this article:
http://www.codeproject.com/KB/webforms/How_group_RButtons.aspx
Upvotes: 0
Reputation: 50728
Why not use the server radio button as in:
<asp:RadioButton id="rad1" runat="server" GroupName="acd" ...
Checked='<%# Eval("valuinfm") %>' />
Note the single quotes around the property value too, when inner quotes are double, you need single on the outside.
Upvotes: 1
Reputation: 18877
Well for starters, this is going to generate multiple radio buttons with the same ID in the browser, which is a no-no. It might also be part of your problem, but it would help to see the code which is actually throwing the error during runtime.
Upvotes: 0