protected void dgVedios_ItemCommand(object source, DataGridCommandEventArgs e) { try { if (e.CommandName == "AddANewRow") { var db = new Pizza15Model(); TextBox txtNames = e.Item.FindControl("txtNamesF") as TextBox; TextBox txtVideoURL = e.Item.FindControl("txtVideoURLF") as TextBox; if (txtNames != null && txtVideoURL != null) { var strQueryMax = db.tbl_Vedios.Max(x => x.ID); int nMaxID = Convert.ToInt32(strQueryMax); var strQuery = new tbl_Vedios(); if (nMaxID != 0) { strQuery.ID = nMaxID + 1; } else { strQuery.ID = 1; } strQuery.Name = txtNames.Text; strQuery.VideoUrl = txtVideoURL.Text; db.tbl_Vedios.Add(strQuery); db.SaveChanges(); } else { lblError.Text = "Error finding the Videos"; } Session["Vodeos"] = null; GetData(); } } catch (Exception ex) { lblError.Text = ex.Message; } }
protected void dgVedios_UpdateCommand(object source, DataGridCommandEventArgs e) { try { string strID = dgVedios.DataKeys[e.Item.ItemIndex].ToString(); int nStrID = Convert.ToInt32(strID); string strVideos = ""; TextBox txtNames = e.Item.FindControl("txtNamesE") as TextBox; TextBox txtVideoURL = e.Item.FindControl("txtVideoURLE") as TextBox; if ((txtNames != null && txtVideoURL != null)) { strVideos = txtNames.Text; var db = new Pizza15Model(); tbl_Vedios UpdateVideos = db.tbl_Vedios.FirstOrDefault(x => x.ID.Equals(nStrID)); if (UpdateVideos != null) { UpdateVideos.Name = txtNames.Text.Trim(); UpdateVideos.VideoUrl = txtVideoURL.Text.Trim(); db.SaveChanges(); } } else { lblError.Text = "Error finding the Video"; } dgVedios.EditItemIndex = -1; dgVedios.ShowFooter = true; Session["Videos"] = null; GetData(); } catch (Exception ex) { lblError.Text = ex.Message; } }