Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hey guys, I have this problem from few weeks. I have a form with radio button list 1.Active 2.Inactive as list items .
In another page I have dataformview to search and edit above filled data. If user did not select any option from the radiobutton list during submission and tries to edit null data in form view it throws an error saying "RadioButtonList' has a SelectedValue which is invalid because it does not exist in the list of items" .How should I approach for this problem. I am using varchar as datatype for radiobutton. Also which datatype would be best for radiobutton (to save data and bind).Do I need to set default value for radiobutton list? Please help me. Appreciate your response.
Here is the sample code of radiobutton submission
XML
<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True"
                   onselectedindexchanged="RadioButtonList1_SelectedIndexChanged"
                   style="text-align: left; font-size: medium;" RepeatDirection="Horizontal"
                   RepeatLayout="Flow" AppendDataBoundItems="True">
                   <asp:ListItem Text="Active">Active</asp:ListItem>
                   <asp:ListItem Text = "Inactive">Inactive</asp:ListItem>


Here is the code for edit item template of formview
XML
<asp:RadioButtonList ID="RadioButtonList3" runat="server"
                            SelectedValue = '<%# Bind("stat") %>'
                            Width="300px" TabIndex="3">
                            <asp:ListItem Text="Active" />

<asp:ListItem Text="Inactive" />


Note; stat is the column name for radiobutton list
Posted
Updated 25-Sep-12 12:13pm
v3

1 solution

employ javascript validation before heading to server side code....
 
Share this answer
 
Comments
Slacker89 25-Sep-12 23:45pm    
Thanks for reply. Could you please elaborate your idea? I can use required field validator at client side but I don't want radio button list to be required field. I want it to take null value as another item such that users can change their selected value in edit item template . This link contains a similar problem but I am not sure of what datatype to actually use for radiobutton list so that I could find null values also.
http://forums.asp.net/t/1070081.aspx/1
[no name] 25-Sep-12 23:53pm    
modify your stored procedure according to ur requirement

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