Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET MySQL VB.NET
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
<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
<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 25-Sep-12 13:12pm
Edited 25-Sep-12 13:13pm
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

employ javascript validation before heading to server side code....
  Permalink  
Comments
sreeharshakakarla at 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
shabari7 at 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)

  Print Answers RSS
0 DamithSL 300
1 Sergey Alexandrovich Kryukov 287
2 OriginalGriff 195
3 Zoltán Zörgő 149
4 Peter Leow 115
0 OriginalGriff 7,510
1 DamithSL 5,519
2 Sergey Alexandrovich Kryukov 5,044
3 Maciej Los 4,961
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 25 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100