Thursday, May 23, 2013

How to check that RadioButtonList has a selected value

Posted by Rahul Kharde at 5:01 AM
RadioButtonList has two property to find out any item is selected or not.

1) SelectedIndex

2) SelectedItem


HTML

<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem Value="0" Selected="True">YES</asp:ListItem>
<asp:ListItem Value="1">NO</asp:ListItem>
</asp:RadioButtonList>

Sometime you need to check to see if a value has been selected before you do anything in coding

CS Code

if (RadioButtonList1.SelectedItem != null)
{
     RadioButtonList1.SelectedItem.Selected = false;
}

Or 

if(RadioButtonList1.SelectedIndex<>-1)
{
     RadioButtonList1.SelectedItem.Selected=false;
}



If you enjoyed this post and wish to be informed whenever a new post is published, then make sure you subscribe to my regular Email Updates. Subscribe Now!


Kindly Bookmark and Share it:

YOUR ADSENSE CODE GOES HERE

0 comments:

Have any question? Feel Free To Post Below:

 

Popular Posts

Recent Comments

© 2011. All Rights Reserved | Help to understand .Net | Template by Blogger Widgets

Home | About | Top