开发者

Problem with HTML radio button inside repeater

I have a HTML radio button inside a 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>

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:


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜