protected void del_Command(object sender, CommandEventArgs e) { if (e.CommandName == "delcm") { foreach (RepeaterItem it in grid_product.Items) { Label n1 = (Label)it.FindControl("lblid"); if (n1.Text == e.CommandArgument.ToString()) { int n = Convert.ToInt32(n1.Text); List <product_image> lim = cl.getProdImage(n); foreach (product_image imgpr in lim) { listim.Add(imgpr); cl.DeleteImgProd(imgpr.id_img); } if (cl.DeleteProduct(n)) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Delete Complete')", true); break; } else { foreach (product_image imgpr1 in listim) { product_image imgtam = new product_image(); imgtam.id_prod = imgpr1.id_prod; imgtam.img_url = imgpr1.img_url; imgtam.sub_img = imgpr1.sub_img; cl.AddimgProd(imgtam); } ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Delete Fail')", true); } } } load_Prod(); } }