asp.net radio button grouping

后端 未结 10 431
余生分开走
余生分开走 2020-12-05 09:47

I am currently having an issue with radio buttons and grouping. I have an asp radio button within a repeater control. I have the group name attribute set to \"Customer\". Wh

相关标签:
10条回答
  • 2020-12-05 10:31

    I had to modify slightly the answer posted above by r3dsky.

    Here's what worked for me:

    $(document).ready(function () {
            $(".divWithGridViewOrRepeater input:radio").attr("name", "yourGroupName");
        }); 
    
    0 讨论(0)
  • 2020-12-05 10:32

    Unfortunately, this is a well known issue with radio buttons within a repeater. One of your only options would be to create a custom server control derived from the RadioButton class and override how it renders.

    EDIT: Here's a sample of what the derived class may look like:

    public class MyRadioButton : RadioButton
    {
        protected override void Render(HtmlTextWriter writer)
        {
            writer.Write("<input id=\"" + base.ClientID + "\" ");
            writer.Write("type=\"radio\" ");
            writer.Write("name=\"" + base.ID + "\" ");
            writer.Write("value=\"" + base.ID + "\" />");
            writer.Write("<label for=\"" + base.ClientID + "\">");
            writer.Write(base.Text);
            writer.Write("</label>");
        }
    }
    
    0 讨论(0)
  • 2020-12-05 10:38

    I finally got around this by creating a plain radio button and setting the value using an server-side eval.

    <input type="radio" name="radCustomer" value='<%#Eval("CustomerNumber") %>' />
    

    Now when the application performs a postback, I check for the value of Request.Form["radCustomer"]. This works flawlessly.

    0 讨论(0)
  • 2020-12-05 10:45

    I had the same issues. I am using Literal as placeholder to render radio button onItemCreated event.

    ASP.Net

    <asp:Repeater ID="rpt" runat="server" OnItemCreated="rpt_OnItemCreated">
        <ItemTemplate>
            <asp:Literal ID="lit" runat="server"></asp:Literal>
        </ItemTemplate>
    </asp:Repeater>
    

    C#

    protected void rpt_OnItemCreated(object sender, RepeaterItemEventArgs e) {
        Literal lit = (Literal)e.Item.FindControl("lit");
        lit.Text = "<input type=\"radio\" name=\"myGroup\">";
    }
    
    0 讨论(0)
提交回复
热议问题