protected void DataList1_DeleteCommand(object sender, DataListCommandEventArgs e) { //string url1 = ((System.Web.UI.WebControls.Image)e.Item.FindControl("CommodityImage")).ImageUrl.ToString(); //if (url1 != null && url1 != "") //{ // string webFilePath = Server.MapPath(url1);//用来删除原有的图片 // System.IO.FileInfo file = new System.IO.FileInfo(webFilePath); // if (file.Exists) // { // file.Delete();//删除 // } // string url3 = ((System.Web.UI.WebControls.Image)e.Item.FindControl("basicImage")).ImageUrl.ToString(); // string webFilePath2 = Server.MapPath(url3);//用来删除原有的图片 // System.IO.FileInfo file2 = new System.IO.FileInfo(webFilePath2); // if (file2.Exists) // { // file2.Delete();//删除 // } //} ExampleArticleBLL examplearticlebll2 = new ExampleArticleBLL();; string id = e.CommandArgument.ToString(); if (examplearticlebll2.Delete(id)) { Response.Write("<script>alert('删除成功');</script>"); } this.Response.Redirect(this.Request.Url.ToString()); }
protected void Delete_Click(object sender, EventArgs e) { for (int i = 0; i < DataList1.Items.Count; i++) { if (((CheckBox)DataList1.Items[i].FindControl("selected")).Checked == true) { object s = ((System.Web.UI.WebControls.HyperLink)DataList1.Items[i].FindControl("Hyperlink3")).Text; ExampleArticleBLL examplearticlebll = new ExampleArticleBLL(); if (examplearticlebll.Delete(s)) { Response.Write("<script>alert('删除成功');</script>"); } } } this.Response.Redirect(this.Request.Url.ToString()); }