views:

363

answers:

3

Hi,

I have a html radio button inside repeater . I m facing two problems

  1. when I m binding Value from code behind(using datatable in code behind) it is throwing error server tag not found.

  2. 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>

anyone is having any idea where I m getting wrong. 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:

A: 

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.

NickLarsen
I knw that with same value it would going to create problem but I m getting my information from code behind. valueinfm is always unique
AB
Really? I thought .net added a bunch of stuff relating to the path of a control to the start of an ID when the control was runat="server" (much to my annoyance in most cases but to avoid exactly what you describe)
vitch
+1  A: 

Hey,

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.

Brian
Thanks Brian it helped but I m not using server control because of the known bug with asp radio buttons and repeater as mentioned by microsoft http://support.microsoft.com/kb/316495
AB
A: 

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

vitch
Thanks for the rpely vitch yah I know abt it but i thought that this problem is only with asp.net radio button if I use html radio button it wud be the case . So the only alternative to this is by creating custom radio button. I was just reluctant to do this thought may be some other approach to do it....
AB
No - once you put a runat="server" on a html radio button .net also takes over and changes the id and name attributes. View source in the generated page to see...
vitch