protected void GetExercise() { using (DefaultConnection db = new DefaultConnection()) { var Exercise = from e in db.Exerciselogs select e; grdExerciselog.DataSource = Exercise.ToList(); grdExerciselog.DataBind(); } }
protected void GetGoals() { using (DefaultConnection db = new DefaultConnection()) { var Goals = from g in db.Goallogs select g; grdGoals.DataSource = Goals.ToList(); grdGoals.DataBind(); } }
protected void GetFoodlog() { using (DefaultConnection db = new DefaultConnection()) { var Foodlog = from f in db.Foodlogs select f; grdFoodlog.DataSource = Foodlog.ToList(); grdFoodlog.DataBind(); } }
protected void GetGoals() { using (DefaultConnection db = new DefaultConnection()) { var Foodlist = from f in db.Foodlists select f; grdFoodlist.DataSource = Foodlist.ToList(); grdFoodlist.DataBind(); } }
protected void GetFoodtype() { using (DefaultConnection db = new DefaultConnection()) { //Get selected day list var Foodlist = from d in db.Foodlists orderby d.FoodID select d; //bind to the dropdown list ddlFoodtype.DataSource = Foodlist.ToList(); ddlFoodtype.DataBind(); //add default option to the dropdown after we fill it ListItem DefaultItem = new ListItem("-Select-", "0"); ddlFoodtype.Items.Insert(0, DefaultItem); } }
protected void btnSave_Click(object sender, EventArgs e) { //connect using (DefaultConnection db = new DefaultConnection()) { //create a new food log and fill the properties Foodlog objC = new Foodlog(); objC.FoodName = txtFoodname.Text; objC.Calories = Convert.ToInt32(txtCalCount.Text); objC.FoodID = Convert.ToInt32(ddlFoodtype.SelectedValue); objC.DayID = Convert.ToInt32(ddlDay.SelectedValue); //save db.Foodlogs.Add(objC); db.SaveChanges(); //redirect Response.Redirect("foodlog.aspx"); } }