Collecting RadioButtonList Controls

Collecting RadioButtonList Controls

In ASP.NET, the RadioButtonList control is used to create a group of radio buttons where only one can be selected at a time. To collect the selected value from the user, you can handle the SelectedIndexChanged event of the RadioButtonList control and use the SelectedValue property to retrieve the selected value.

Here is an example of how to create and collect data from a RadioButtonList control in ASP.NET:

Add a RadioButtonList control to your ASP.NET page. You can do this by dragging and dropping the control from the toolbox onto the page.

<asp:RadioButtonList ID=”RadioButtonList1″ runat=”server”>

    <asp:ListItem Text=”Option 1″ Value=”1″ />

    <asp:ListItem Text=”Option 2″ Value=”2″ />

    <asp:ListItem Text=”Option 3″ Value=”3″ />

</asp:RadioButtonList>

In your code-behind file, handle the SelectedIndexChanged event of the RadioButtonList control.

protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)

{

    // Retrieve the selected value

    string selectedValue = RadioButtonList1.SelectedValue;

    // Do something with the selected value

    // …

} When the user selects a different option in the RadioButtonList, the SelectedIndexChanged event is triggered and the selected value is retrieved using the SelectedValue property. You can then use this value to perform some action in your code-behind file.

The ASP.NET RadioButtonList control allows you to create many radio buttons with one control. In this section, you build a survey form, work with the Collection editor, and hook up an event handler.

Creating the basic page interface

The survey interface consists of a prompt, a set of radio buttons as choices, a button, and an area for a response. Follow these steps to create the basic interface.

  • In the ASP.NET page Design view, add a Label control with the ID lblPrompt and set the Text value to Rate Your Fear of the Borg.
  • From the Toolbox, drop a RadioButtonList control on the design surface and set its ID to rblBorg.
  • Add another Label with the ID lblResponse and a Button control.

Apply for ASP.NET Certification Now!!

https://www.vskills.in/certification/certified-aspnet-programmer

Back to Tutorial

Punctuation Rules
Removing array values

Get industry recognized certification – Contact us

keyboard_arrow_up
Open chat
Need help?
Hello 👋
Can we help you?