protected void Btndeletealb_Click(object sender, EventArgs e) { StringBuilder strSql = new StringBuilder(string.Empty); StringBuilder strsql1 = new StringBuilder(string.Empty); for (int i = 0; i < Alblist.Items.Count; i++) { CheckBox chk = Alblist.Items[i].FindControl("CheckBox3") as CheckBox; ImageButton img = Alblist.Items[i].FindControl("ImageButton5") as ImageButton; if (chk != null) { if (chk.Checked) { string imgurl = img.ImageUrl; string id = img.CommandArgument; SqlCommand cmdsel = new SqlCommand("select * from Alb_Photo1 where alb_id='" + Convert.ToInt16(id) + "'", cn); cn.Open(); SqlDataAdapter adp1 = new SqlDataAdapter(cmdsel); cmdsel.ExecuteNonQuery(); DataSet ds1 = new DataSet(); adp1.Fill(ds1, "Alb_Photo1"); int row = ds1.Tables["Alb_Photo1"].Rows.Count; for (int j = 0; j < row; j++) { string imagepath = Server.MapPath(ds1.Tables["Alb_Photo1"].Rows[j][2].ToString()); FileInfo filepath = new FileInfo(imagepath); if (filepath.Exists) { filepath.Delete(); } string query1 = "delete from Alb_Photo1 where alb_id='" + Convert.ToInt64(id) + "'"; strsql1.Append(query1); } SqlCommand cmd2 = new SqlCommand(strsql1.ToString(), cn); cmd2.ExecuteNonQuery(); cn.Close(); string path1 = Server.MapPath(imgurl); FileInfo file = new FileInfo(path1); if (file.Exists) { file.Delete(); } string query = "delete from Album1 where id='" + Convert.ToInt64(id) + "'"; strSql.Append(query); } } } cn.Open(); SqlCommand cmd = new SqlCommand(strSql.ToString(), cn); cmd.ExecuteNonQuery(); cn.Close(); Alblist.DataBind(); }
protected void Btnalbdelete_Click(object sender, EventArgs e) { SubPanelalbdelete.Visible = true; SubPanelphotodelete.Visible = false; Alblist.DataBind(); }