tags:

views:

80

answers:

1

Trying to setup a regular Radiobutton in a repeater

<asp:Repeater ID="Repeater1" runat="server">
                    <ItemTemplate>
                        <input type="radio" name="OptGroup" id="rbEmail" value="<%=ID %>"/><label for="rbEmail"><%=Action %></label>
                    </ItemTemplate>
                </asp:Repeater>

I'm trying to think through if I'm missing anything here. I'll have a group of radiobuttons and I believe I can't just hard code the id. That I need a unique ID for each right?

+1  A: 

If I'm reading this right, you're missing the datasource for the repeater, and "ID" and "Action" are part of that datasource? In that case, you want something more like this:

<asp:Repeater ID="Repeater1" runat="server">
                    <ItemTemplate>
                        <input type="radio" name="OptGroup" id='<%#"rbEmail"+Eval("ID")%>' value='<%# Eval("ID") %>'/><label for="rbEmail"><%# Eval("Action") %></label>
                    </ItemTemplate>
                </asp:Repeater>
Joel Coehoorn
Thanks. And I think I can use <%#Container.DataItem.FieldName instead of Eval
Joel, there was an extra = sign and the quotes weren't mismatched, I edited, I hope you don't mind.
bendewey
or even simply <%=ID %>
but doesn't the for attribute have to also have '<%#"rbEmail"+Eval("ID")%>'
Oops: yes, those need to match.
Joel Coehoorn