protected void gridView_RowDeleting(object sender, GridViewDeleteEventArgs e) { int NewsID = (int)gridView.DataKeys[e.RowIndex].Value; bll.Delete(NewsID); BindData(); }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { Maticsoft.BLL.NewsManage.News bll = new Maticsoft.BLL.NewsManage.News(); string id = Request.Params["id"]; bll.Delete(int.Parse(id)); Response.Redirect("index.aspx"); } }
protected void gridView_RowDeleting(object sender, GridViewDeleteEventArgs e) { int NewsID = (int)gridView.DataKeys[e.RowIndex].Value; string strpath = Server.MapPath("~/upload/Temp/"); string strCopypath = Server.MapPath("~/upload/img/"); string strCopypathaff = Server.MapPath("~/upload/affix/"); //删除文章里面的图片 Maticsoft.BLL.NewsManage.NewsImages bllimg = new Maticsoft.BLL.NewsManage.NewsImages(); DataSet ds = bllimg.GetNewsImagesList(-1, NewsID, false); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { try { if (File.Exists(strpath + ds.Tables[0].Rows[i]["LinkUrl"].ToString())) { File.Delete(strpath + ds.Tables[0].Rows[i]["LinkUrl"].ToString()); } if (File.Exists(strCopypath + ds.Tables[0].Rows[i]["LinkUrl"].ToString())) { File.Delete(strCopypath + ds.Tables[0].Rows[i]["LinkUrl"].ToString()); } } catch { } } bllimg.DeletebyNewsId(NewsID); //删除文章里面的附件 Maticsoft.BLL.NewsManage.NewsAffix bllaff = new Maticsoft.BLL.NewsManage.NewsAffix(); DataSet ds1 = bllaff.GetNewsAffixList(-1, NewsID, false); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { try { if (File.Exists(strpath + ds1.Tables[0].Rows[i]["LinkUrl"].ToString())) { File.Delete(strpath + ds1.Tables[0].Rows[i]["LinkUrl"].ToString()); } if (File.Exists(strCopypathaff + ds1.Tables[0].Rows[i]["LinkUrl"].ToString())) { File.Delete(strCopypathaff + ds1.Tables[0].Rows[i]["LinkUrl"].ToString()); } } catch { } } bllaff.DeletebyNewsId(NewsID); bll.Delete(NewsID); BindData(); }