protected void VeEditListView_ItemCommand(object sender, ListViewCommandEventArgs e) { string[] commandArgs = e.CommandArgument.ToString().Split(new char[] { ',' }); string veId = commandArgs[0]; string veImgId = commandArgs[1]; Guid veGuid = Guid.Parse(veId); Guid imgGuid = Guid.Parse(veImgId); if (e.CommandName == "SetAsMain") { CarClass cc = new CarClass(Profile.UserName); cc.SetMainImage(imgGuid, veGuid); UserControl ucx = (UserControl)LoadControl("~/Controls/UserNoticeModal.ascx"); Label txtLabel = (Label)ucx.FindControl("TextLabel"); txtLabel.Text = "Success!"; Form.Controls.Add(ucx); } if (e.CommandName == "DeleteImg") { using (SwapEntities ent = new SwapEntities()) { var delImg = (from tbl in ent.VeImages where tbl.Id == imgGuid select tbl).SingleOrDefault(); if (delImg != null) { string imgPath = delImg.ImageUrl; string serverPath = Server.MapPath(imgPath); try { System.IO.File.Delete(serverPath); } catch { } ent.DeleteObject(delImg); ent.SaveChanges(); UserControl ucx = (UserControl)LoadControl("~/Controls/UserNoticeModal.ascx"); Label txtLabel = (Label)ucx.FindControl("TextLabel"); txtLabel.Text = "Success!"; Form.Controls.Add(ucx); } } } CarsGridView.DataSourceID = "CarsDataSource"; CarsGridView.DataBind(); }
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { int rowIndex = Convert.ToInt32(e.CommandArgument); GridViewRow myRow = GridView1.Rows[rowIndex]; Label veIdLbl = (Label)myRow.FindControl("VeId"); Label veImgLbl = (Label)myRow.FindControl("ImgId"); Guid veGuid = Guid.Parse(veIdLbl.Text); Guid imgGuid = Guid.Parse(veImgLbl.Text); if (e.CommandName == "SetAsMain") { CarClass cc = new CarClass(Profile.UserName); cc.SetMainImage(imgGuid, veGuid); BindPage(veGuid); UserControl ucx = (UserControl)LoadControl("~/Controls/UserNoticeModal.ascx"); Label txtLabel = (Label)ucx.FindControl("TextLabel"); txtLabel.Text = "Success!"; Form.Controls.Add(ucx); } if (e.CommandName == "DeleteImg") { using (SwapEntities ent = new SwapEntities()) { var delImg = (from tbl in ent.VeImages where tbl.Id == imgGuid select tbl).SingleOrDefault(); if (delImg != null) { string imgPath = delImg.ImageUrl; string serverPath = Server.MapPath(imgPath); try { System.IO.File.Delete(serverPath); } catch { } ent.DeleteObject(delImg); ent.SaveChanges(); BindPage(veGuid); UserControl ucx = (UserControl)LoadControl("~/Controls/UserNoticeModal.ascx"); Label txtLabel = (Label)ucx.FindControl("TextLabel"); txtLabel.Text = "Success!"; Form.Controls.Add(ucx); } } } }