Sample RadioButtonList on event SelectedIndexChanged in ASP.Net using C#

Now let's examine how to use RadioButtonList on event SelectedIndexChanged in asp.net using C#. I have a RadioButtonList and a Label . When I click on each items of RadioButtonList, the label will display the text that i want to show. Please see example below:

Form design:

<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="true" onselectedindexchanged="RadioButtonList1_SelectedIndexChanged" >          
            <asp:ListItem  Value="1" Selected="True" >20 % </asp:ListItem>
            <asp:ListItem  Value="2" >40 % </asp:ListItem>
            <asp:ListItem  Value="3" >70 %</asp:ListItem>
</asp:RadioButtonList>
<asp:Label ID="lblDicount" runat="server" ></asp:Label

Code Behind:

 protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //select radiobutton  20 %
            if (RadioButtonList1.SelectedValue.ToString() == "1") {
                lblDicount.Text = "Discount 20 % ";
            }
            //select radiobutton  40 %
            else if (RadioButtonList1.SelectedValue.ToString() == "2") {
                lblDicount.Text = "Discount 40 %";
            }
            //select radiobutton  70 %
            else if (RadioButtonList1.SelectedValue.ToString() == "3") {
                lblDicount.Text = "Discount 70%";
            }
        }

Done....Let's try it :D
  
Sample RadioButtonList on event SelectedIndexChanged in ASP.Net using C# Sample RadioButtonList on event SelectedIndexChanged in ASP.Net using C# Reviewed by BeiLover on 10:44 PM Rating: 5

No comments:

Powered by Blogger.