Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,
I saved radiobutton list value in database like "Male" or "Female".Now i want to retrieve that data from database to radiobuttonlist.If Male in database i want to check the Radionbuttonlist(Male) value other wise uncheck the radiobuttonlist(Female) value.


Thanks and Regards
Hari
Posted

C#
void RefreshGender(string gender)
{
    if (gender == "male")
        RadioButtonList1.Items[0].Selected = true;
    else if (gender == "female")
        RadioButtonList1.Items[1].Selected = true;
    else
        RadioButtonList1.Items[2].Selected = true;
}
 
Share this answer
 
Hi All,
I got Solution in Single line of code.

rdbgender.SelectedIndex = Convert.ToInt32(rdbgender.Items.IndexOf(rdbgender.Items.FindByText(ds.Tables[0].Rows[0]["Gender"].ToString())));
 
Share this answer
 
Comments
loony malik 27-May-13 17:46pm    
Thank you, it worked perfectly!
Member 12655835 5-Oct-16 6:46am    
thanku
you just write code on the page load to select the table value ,and get it in textbox or as string ,and use that value to check the radio button male or female


SQL
if (gender == "male")
       RadioButtonList1.Items[0].Selected = true;
   else if (gender == "female")
       RadioButtonList1.Items[1].Selected = true;
 
Share this answer
 
Comments
Hari Krishna Prasad Inakoti 23-Jan-13 6:38am    
hi thanq for ur answer.
Already i used this code.I want code in single line.

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