This is so damn stupid but driving me absolutely fing crazy.
<input type="radio" name="OptGroup" id="<%#"rbEmail" + ((Action)Container.DataItem).ID %>" value="<%#((Action)Container.DataItem).ID %>" runat="server" /><label for="<%#"rbEmail" + ((Action)Container.DataItem).ID %>"><%#((Action)Container.DataItem).Action %></label>
What am I doing wrong here! I've also tried:
<input type="radio" name="OptGroup" id='<%#"rbEmail" + ((Action)Container.DataItem).ID %>' value='<%#((Action)Container.DataItem).ID %>' runat="server" /><label for='<%#"rbEmail" + ((Action)Container.DataItem).ID %>'><%#((Action)Container.DataItem).Action %></label>
and
<input type="radio" name="OptGroup" id="<%#'rbEmail' + ((Action)Container.DataItem).ID %>" value="<%#((Action)Container.DataItem).ID %>" runat="server" /><label for="<%#'rbEmail' + ((Action)Container.DataItem).ID %>"><%#((Action)Container.DataItem).Action %></label>
I specifically do not want to use an asp.net radiobutton due to the problems with GroupName it creates while inside a repeater. I want to use a bare radio button and bind its values to my datasource.
Do you need to access the control server-side? If not, take off the runat="server", you cannot databind to the ID property for a server control. Not sure if thats the problem, since that should give you a different error
EDIT:
Something like this should suit your purposes..
<asp:Repeater runat="server">
    <ItemTemplate>
        <label><input type="radio" name="rbEmail" value='<%# ((Action)Container.DataItem).ID %>' /><%# ((Action)Container.DataItem).Action %></label>
    </ItemTemplate>
</asp:Repeater>
Then in the postback, you can get the value from Request.Form["rbEmail"]
EDIT2:
Fully tested simple page example..
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:Repeater ID="Repeater1" runat="server">
            <ItemTemplate>
                <label><input type="radio" name="rbEmail" value='<%# Container.DataItem %>' /><%# Container.DataItem %></label>
            </ItemTemplate>
        </asp:Repeater>
        <asp:Button ID="submit" runat="server" OnClick="submit_Click" Text="submit" />
    </form>
</body>
</html>
Default.aspx.cs
using System;
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Repeater1.DataSource = new string[] { "Hello", "World" };
        Repeater1.DataBind();
    }
    protected void submit_Click(object sender, EventArgs e)
    {
        Response.Write(Request.Form["rbEmail"]);
    }
}
Use single quotes for your html. For example:
<input type='radio' name='OptGroup' id='<%#"rbEmail" + ((Action)Container.DataItem).ID %>' value='<%#((Action)Container.DataItem).ID %>' runat='server' /><label for='<%#"rbEmail" + ((Action)Container.DataItem).ID %>'><%#((Action)Container.DataItem).Action %></label>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With