tags:

views:

17

answers:

2

Hi,

I have a repeater control in my page. I need to have a radio button in all the rows(Item template) on checking an radio button the remaining radio buttons must unchecked.

How to do this?

Thanks in advance, Tor

A: 

Just add a OnCheckedChanged event to the radio button, loop all the radiobuttons in the repeater to uncheck them. You can use UpatePanel if you do not want postback.

.aspx

<asp:Repeater ID="Repeater1" runat="server" >
    <ItemTemplate>
        <asp:RadioButton ID="RadioButton1" runat="server" OnCheckedChanged="RadioButton1_OnCheckedChanged" AutoPostBack="true" />
    </ItemTemplate>
</asp:Repeater>

.cs

protected void RadioButton1_OnCheckedChanged(object sender, EventArgs e)
{
    foreach (RepeaterItem item in Repeater1.Items)
    {
        RadioButton rbtn = (RadioButton)item.FindControl("RadioButton1");
        rbtn.Checked = false;
    }
    ((RadioButton)sender).Checked = true;
}
Lee Sy En
@Lee Sy En: For the Above Example, if you add the Property "GroupName" for control <asp:RadioButton>, It will add all the radioButton under same group so only one Radio Button will be selected.
Shivkant
oh yeah.. we should use that instead!
Lee Sy En
A: 

If you are using an ASP.NET RadioButton control, set the GroupName property for all of them to be the same value. If you are using actual INPUT tags, then set the Name property to be the same for them all. This will make the browser treat them all as a set, where only one can be selected at a time (i.e., it will do what you want automatically).

patmortech