selecting one value from checkboxlist

Posted by Chaithragm under C# on 3/12/2013 | Points: 10 | Views : 3102 | Status : [Member] | Replies : 2
<asp:CheckBoxList ID="nationality_chk" runat="server" RepeatDirection="Horizontal">
<asp:ListItem>Indian</asp:ListItem>
<asp:ListItem>Foreigner</asp:ListItem>
</asp:CheckBoxList>
i have to select one value from the list and store that value to database
im getting error while parsing the value
how to do this..




Responses

Posted by: Jayakumars on: 3/12/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

change lik this

<asp:CheckBoxList ID="nationality_chk" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Text ="Indian" Value="1"></asp:ListItem>
<asp:ListItem Text ="Foreigner" Value="2"></asp:ListItem>
</asp:CheckBoxList>

Mark as Answer if its helpful to you

Kumaraspcode2009@gmail.com

Chaithragm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Santhi on: 3/12/2013 [Member] Starter | Points: 25

Up
0
Down
Hi

What is the datatype of the value which you are storing on the database?
if it is an integer , you cannot convet this string value...

If you dont assign separate values for list items.
Then it takes text as the selected value.

When you try to convert this string value to an integer.
It will throw error.

So, you have to do according to your requirement.
if you need to store the values as an integer. then you need to have value for all the list items.


Thanks & Regards,
Santhi .V

Chaithragm, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response