Rectangle 27 1

In the server side do as follows:

protected void rptRepeaterName_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    RadioButton rdbRadioButtonName = e.Item.FindControl("rdbRadioButtonName") as RadioButton;
    Repeater rptRepeaterName = sender as Repeater;
    rdbRadioButtonName.Attributes.Add("onclick", string.Format("return radioSelected('{0}', '{1}')", rptRepeaterName.ClientID, rdbRadioButtonName.ClientID));
}

In the javascript do as follows

function radioSelected(rptpricelevel, rdbPriceLevel)
{        
    for (cnt = 0; cnt<100; cnt++)
    {            
        var rdbId = rptpricelevel;
        if(cnt < 10)
        {
            rdbId = + '_ctl0' + cnt + '_rdbRadioButtonName';
        }
        else
        {
            rdbId = + '_ctl' + cnt + '_rdbRadioButtonName';
        }
        var rdb = document.getElementById(rdbId);
        if(rdb != null)
        {
            if(rdbId != rdbPriceLevel)
            {
                rdb.checked = false;
            }
        }
     }         
}

radio button - RadioButtons not grouping properly in an ASP.NET 2.0 re...

asp.net radio-button asp.net-2.0 repeater
Rectangle 27 1

A coworker ran across this issue and implemented a jQuery solution. Here's an excerpt of it:

That gave me the radio button functionality that I wanted, but it prevented me from getting the selected radio button on postback. So I decided to just implement the radio button functionality manually.

var radios = $("input:radio");
radios.click(function() {
     radios.removeAttr('checked');
     $(this).attr('checked', 'checked');
     return true;
});

Which gave me the correct functionality and I could still get the selected radio button and textbox on postback. Probably not the most elegant solution, but I couldnt find any other way to do it.

radio button - RadioButtons not grouping properly in an ASP.NET 2.0 re...

asp.net radio-button asp.net-2.0 repeater
Rectangle 27 0

In the server side do as follows:

protected void rptRepeaterName_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    RadioButton rdbRadioButtonName = e.Item.FindControl("rdbRadioButtonName") as RadioButton;
    Repeater rptRepeaterName = sender as Repeater;
    rdbRadioButtonName.Attributes.Add("onclick", string.Format("return radioSelected('{0}', '{1}')", rptRepeaterName.ClientID, rdbRadioButtonName.ClientID));
}

In the javascript do as follows

function radioSelected(rptpricelevel, rdbPriceLevel)
{        
    for (cnt = 0; cnt<100; cnt++)
    {            
        var rdbId = rptpricelevel;
        if(cnt < 10)
        {
            rdbId = + '_ctl0' + cnt + '_rdbRadioButtonName';
        }
        else
        {
            rdbId = + '_ctl' + cnt + '_rdbRadioButtonName';
        }
        var rdb = document.getElementById(rdbId);
        if(rdb != null)
        {
            if(rdbId != rdbPriceLevel)
            {
                rdb.checked = false;
            }
        }
     }         
}

radio button - RadioButtons not grouping properly in an ASP.NET 2.0 re...

asp.net radio-button asp.net-2.0 repeater
Rectangle 27 0

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

<asp:Repeater ID="rpt" runat="server" OnItemCreated="rpt_OnItemCreated">
    <ItemTemplate>
        <asp:Literal ID="lit" runat="server"></asp:Literal>
    </ItemTemplate>
</asp:Repeater>
protected void rpt_OnItemCreated(object sender, RepeaterItemEventArgs e) {
    Literal lit = (Literal)e.Item.FindControl("lit");
    lit.Text = "<input type=\"radio\" name=\"myGroup\">";
}

Note that you must specify the name attribute (and not solely the id) for the radio-buttons to show up in Request.Form on postback!

repeater - asp.net radio button grouping - Stack Overflow

asp.net repeater radio-button
Rectangle 27 0

There is not a value attribute for the asp radio button control.

He probably meant the 'Text' property. ;)

That's a no go. I knew that it was just going to add a label to it, but I figured that I would try it anyways.

repeater - asp.net radio button grouping - Stack Overflow

asp.net repeater radio-button
Rectangle 27 0

Question? Do you need these radio buttons to be server controls (i.e. do you need the runat=server tag)? If not, you could simply have regular html radio buttons on the column and bind any properties to it using the <%#Eval("Property")%> syntax. Just a thought

<input type='radio' class='myRadioButtonClass' name='myGroupName' data-rowID='<%#Eval("UniqueID") %>' />
$('.myRadioButtonClass')

@Mr. Jefferson Good :) I'm glad it worked.

radio button - RadioButtons not grouping properly in an ASP.NET 2.0 re...

asp.net radio-button asp.net-2.0 repeater
Rectangle 27 0

I made my radiobutton have autopostback set to true, and then in the event handler set all the other radio buttons to BE unselected.

Not ideal, but I need lots control over the visibility and enabled attributes of the radiobutton, and it seemed easier to let ASP.NET control that rather than resorting to client side script.

repeater - asp.net radio button grouping - Stack Overflow

asp.net repeater radio-button
Rectangle 27 0

$(document).ready(function () {
        $("#divWithGridViewOrRepeater input:radio").attr("name", "yourGroupName");
    });

Which this "works" there's a lot of potential for confusion here. If you're really going with this method be sure you HEAVILY document what is going on.

repeater - asp.net radio button grouping - Stack Overflow

asp.net repeater radio-button
Rectangle 27 0

Question? Do you need these radio buttons to be server controls (i.e. do you need the runat=server tag)? If not, you could simply have regular html radio buttons on the column and bind any properties to it using the <%#Eval("Property")%> syntax. Just a thought

<input type='radio' class='myRadioButtonClass' name='myGroupName' data-rowID='<%#Eval("UniqueID") %>' />
$('.myRadioButtonClass')

@Mr. Jefferson Good :) I'm glad it worked.

radio button - RadioButtons not grouping properly in an ASP.NET 2.0 re...

asp.net radio-button asp.net-2.0 repeater
Rectangle 27 0

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.

If we need the AutoPostback functionality?

repeater - asp.net radio button grouping - Stack Overflow

asp.net repeater radio-button
Rectangle 27 0

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>");
    }
}

Wow. This is a pretty big hole in functionality. Bleh.

This is based on the idea that you could have a radiobutton group within an item template of the repeater (multiple radio buttons on the same row). In that case you would want unique grouping based on the mangled id, but most of the time people want what the OP tried to do.

<input />
<label>
writer.Write("<input id='" + base.ClientID + "' type='radio' name='" + base.ID + "' value='" + base.ID + "' /><label for='" + base.ClientID + "'>" + base.Text + "</label>");

repeater - asp.net radio button grouping - Stack Overflow

asp.net repeater radio-button
Rectangle 27 0

This is a well known bug with the ASP.NET Repeater using RadioButtons: here best solution in my opinion

repeater - asp.net radio button grouping - Stack Overflow

asp.net repeater radio-button
Rectangle 27 0

A coworker ran across this issue and implemented a jQuery solution. Here's an excerpt of it:

That gave me the radio button functionality that I wanted, but it prevented me from getting the selected radio button on postback. So I decided to just implement the radio button functionality manually.

var radios = $("input:radio");
radios.click(function() {
     radios.removeAttr('checked');
     $(this).attr('checked', 'checked');
     return true;
});

Which gave me the correct functionality and I could still get the selected radio button and textbox on postback. Probably not the most elegant solution, but I couldnt find any other way to do it.

radio button - RadioButtons not grouping properly in an ASP.NET 2.0 re...

asp.net radio-button asp.net-2.0 repeater
Rectangle 27 0

Use HTML radio button instead of ASP Radio button:-

<input type="radio" name="GoogleCalenderList" />

I need to use this radio button server side can we find this HTML control server side as i need to get Calenderid on the basics of radio button selection

@GauravKaushik - Okay, are you using client side code? jQuery or something, if so, you can continue using your asp radio button and change its group name at client side.

thanx dude...i tried with client side code to change its group name. and it worked..

asp.net - Radio button grouping not working in repeater control - Stac...

asp.net repeater