I am trying to make a meal planner, I have a GridView
of foods and their nutritional values and a CheckBox
row. I want to be able to check as many foods as I wish. Then click the Add Food button and have the information of the checked rows inserted into my database.
Here is what I have which is not working:
protected void AddFoodbtn_Click(object sender, EventArgs e)
{
CheckBox rowcheck = (CheckBox)GridView2.FindControl("SelectFoodchk");
for (int i = 0; 0 < GridView2.Rows.Count; i++)
{
if (rowcheck.Checked)
{
GridViewRow viewrow = GridView2.Rows[i];
string foodid = viewrow.Cells[0].Text.ToString();
}
}
}