Site icon Tutorial

Capturing the Survey Choice

Capturing the Survey Choice

To capture the survey choice selected by the user using the RadioButtonList control in ASP.NET, you can use the following steps:

Place the RadioButtonList control on your ASP.NET page, and set its ID and ListItem values in the Properties window or directly in the HTML code.

Example:

<asp:RadioButtonList ID=”surveyChoices” runat=”server”>

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

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

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

</asp:RadioButtonList>

In the code-behind file of the ASP.NET page, handle the Click event of a button or any other event that triggers the survey choice capture.

Example:

protected void submitButton_Click(object sender, EventArgs e)

{

    string choice = surveyChoices.SelectedValue;

    // use the selected survey choice in your application logic

} In this example, the SelectedValue property of the RadioButtonList control is used to capture the value of the selected survey choice, which can then be used in the application logic.

So far, the survey form is just a interface with no logic. Follow these steps to capture the user’s choice and show that choice in the browser:

The IDE automatically inserts the following event handler code (formatted differently here) into the page:

protected void Page_Load(object sender, EventArgs e)

{

}

lblResponse.Text = rbl.SelectedValue;

When you run the page and click the button, the click causes the page to submit its data (a postback). A Page Load event occurs just before ASP.NET completes construction of the page. The Load event handler code looks at the RadioButtonList (rbl) and extracts whatever is in its SelectedValue property. The code assigns the SelectedValue value as the Text property of the Label so the user can see the results.

Apply for ASP.NET Certification Now!!

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

Back to Tutorial

Exit mobile version