I used 4 checkbox in my application and created an integer list to add value if the checkbox is checked. The value will be stored in my database using sqlite. This is my code :
List<int> hobid = new List<int>();
private void Button_Click_1(object sender, RoutedEventArgs e)
{
if (Convert.ToBoolean(cricket.IsChecked))
{
hobid.Add(1);
}
else if (Convert.ToBoolean(football.IsChecked))
{
hobid.Add(2);
}
else if (Convert.ToBoolean(music.IsChecked))
{
hobid.Add(3);
}
else if (Convert.ToBoolean(reading.IsChecked))
{
hobid.Add(4);
}
int rec;
string strInserthob = "Insert into User_hobbies (User_id,Hobbies_id) values (@User_id,@Hobbies_id)";
//Here insertion is done..
for (int i = 0; i < hobid.Count; i++)
{
User_hobbies txt = new User_hobbies
{
User_id = userid,
Hobbies_id = hobid[i]
};
rec = (Application.Current as App).db.Insert<User_hobbies>(txt, strInserthob);
}
}
Can you suggest me how to get the value in a list whatever checkbox is checked.