简体   繁体   中英

Radio Buttons in ASP.NET

I'm bit new to .NET. I am using Radio buttons inside a panel in a web page. (Since group boxes are not there). But when I click on each radio button they all are checked. They are not acting as a group but single units.

Do I need to remove the panel here? Please help me.

You're probably missing GroupName

<asp:RadioButton id="button1" runat="server" GroupName="MyGroup" Text="Button 1" />
<asp:RadioButton id="button2" runat="server" GroupName="MyGroup" Text="Button 2" />
<asp:RadioButton id="button3" runat="server" GroupName="MyGroup" Text="Button 3" />

You can use the Radiobuttonlist in ASP.NET toolbar.

And in the SelectedIndexChanged event of the radiobuttonlist you can do what ever you want as you wish. (rblist is the radiobuttonlist )

protected void rbList_SelectedIndexChanged(object sender, EventArgs e)
{
    if (rbList.Items[0].Selected)
    {
        lblHeader.Text = "You selected first option";
    }
}

您想要的是<asp:RadioButtonList>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM