Click here to Skip to main content
15,900,725 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
I have one RadioButtonList control.
How to make changes on selection of just one raido button of the list ? While selection of radio button other than this mentioned above, no change should occur.

I want to make change only when last radio button(No stipend) from below code is checked.

ASP.NET
<asp:RadioButtonList ID="RadioButtonList1" runat="server" 
                        RepeatDirection="Horizontal">
                        <asp:ListItem>Fixed</asp:ListItem>
                        <asp:ListItem>Variable</asp:ListItem>
                        <asp:ListItem>Expenses Covered</asp:ListItem>
                        <asp:ListItem >No Stipend</asp:ListItem>
                    </asp:RadioButtonList>
Posted

change code like this

XML
<asp:RadioButtonList ID="RadioButtonList1" AutoPostBack="true" runat="server"
                       RepeatDirection="Horizontal" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
                       <asp:ListItem>Fixed</asp:ListItem>
                       <asp:ListItem>Variable</asp:ListItem>
                       <asp:ListItem>Expenses Covered</asp:ListItem>
                       <asp:ListItem >No Stipend</asp:ListItem>
                   </asp:RadioButtonList>


in cs page add following

C#
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (RadioButtonList1.SelectedItem.Text == "No Stipend")
        {
            //your code
        }
    }
 
Share this answer
 
v5
Comments
jayraj86 7-May-14 8:25am    
Nothing happens when I select this last radio button ;/
Darshan.Pa 7-May-14 8:27am    
put AutoPostBack="True" in <asp:RadioButtonList AutoPostBack="True" ....
jayraj86 7-May-14 8:30am    
Thanks a lot!!
Use the OnSelectedIndexChanged event[^]

In that event you can check if the selected item ha No Stipend has text or the value from the database.

In the event you can do
C#
RadioButtonList rdbl = (RadioButtonList)sender;
var selectedValue = rdbl.SelectedItem.Value;
var selectedText = rdbl.SelectedItem.Text;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900