Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi i search lot on this but i didn't get any solution so i thought i should ask here my question is quite different i have a grid-view in which i have an image button to delete department

Now according to my application when i create department a folder with that department name will create and in my upload images page user can user those department to save images in those department folder with and their path store in the database.

upload image page.cs

C#
protected void btnSubmit_Click1(object sender, EventArgs e)
{
    string DepartmentID = ddlDepartment.SelectedValue;

    string Description = tbImageName.Text.Trim();

    string Priority = lblPriority.Text;
    //Get imagename from fileupload control
    string imgName = fileuploadimages.FileName.ToString();
    //sets the image path if exist then store image in that place else create new one
    string imgPath = "Images/Departments/" + "" + ddlDepartment.SelectedValue + "/";
    bool IsExists = System.IO.Directory.Exists(Server.MapPath(imgPath));
    if (!IsExists)
        System.IO.Directory.CreateDirectory(Server.MapPath(imgPath));
    //then save it to the Folder
    fileuploadimages.SaveAs(Server.MapPath(imgPath + imgName));
    //Open the database connection
    con.Open();
    //Query to insert * into images into database
    SqlCommand cmd = new SqlCommand("Insert into Images(ImageName,Description,Path,Priority,DepartmentID) values(@ImageName,@Description,@Path,@Priority,@DepartmentID)", con);
    //Passing parameters to query
    cmd.Parameters.AddWithValue("@ImageName", imgName);
    cmd.Parameters.AddWithValue("@Description", Description);
    cmd.Parameters.AddWithValue("@Path", imgPath + imgName);
    cmd.Parameters.AddWithValue("@Priority", Priority);
    cmd.Parameters.AddWithValue("@DepartmentID", DepartmentID);
    cmd.ExecuteNonQuery();
    //Close dbconnection
    con.Close();
    tbImageName.Text = string.Empty;
    Response.Redirect(Request.RawUrl);
}


n department_master page

When user click on delete image button a confirmation message box will appear to ask yes or no if yes then department delete from the database with folder and images now that part is done by me

for this code i used is department.aspx.cs:

C#
protected void gvDetails_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
    string id = gvDetails.DataKeys[e.RowIndex].Values["DepartmentID"].ToString();
    con.Open();
    SqlCommand cmd = new SqlCommand("Select * from Department_Master where DepartmentID=" + id, con);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    da.Fill(ds);

    DataTable dt = ds.Tables[0];
    for (int i = 0; i < dt.Rows.Count; i++)
    {
        string imgPath = "Images/Departments/" + "" + dt.Rows[i]["DepartmentID"] + "/";
        bool IsExists = System.IO.Directory.Exists(Server.MapPath(imgPath));
        if (IsExists)
            System.IO.Directory.Delete(Server.MapPath(imgPath), true);
    }

    con.Close();


    con.Open();
    SqlCommand cmd1 = new SqlCommand("Delete from Images where DepartmentID=" + id + "; delete from Department_Master where DepartmentID=" + id, con);
    int result = cmd1.ExecuteNonQuery();
    con.Close();
    if (result == 1)
    {
        BindDetails();
        lblresult.ForeColor = Color.Red;
        lblresult.Text = id + " details deleted successfully";
    }
    BindDetails();
}

<asp:ImageButton ID="imgbtnDelete" CommandName="Delete" Text="Edit"  runat="server" ImageUrl="~/Images/delete.jpg" ToolTip="Delete" Height="20px" Width="20px"  önClientClick=" return confirm('Are you sure you want to delete');"/>


now what i want is when user click on image button a message box comes with yes or no and when user click on yes to delete department another confirmation box will appear to ask whether they want to save those image or not and if they click on yes then show them the option where they can save those images and if no then delete department with folder and images just like the department.aspx.cs page code
Posted

This example is similar to what you require:

JavaScript
<pre lang="xml"><script type="text/javascript">
    function chk() {
        var x = window.confirm("Are you sure you are ok?")
        if (x) {
            
            var y = window.confirm("Really sure?")
            if (y)
                window.alert("Good!")
            else
                window.alert("Too bad")
        }
        else
            window.alert("Too bad")
    }
</script>


Call this function on :

HTML
<input type="submit" value="sub1" onclick="chk();" />
 
Share this answer
 
Comments
amitesh1989 15-Jul-13 7:19am    
hi @priyanka7777 your solution is good when user click on yes another message box will appear but when i click yes on first message box my folder and images deleted i want if user click on no= i don't want to save images in second message box then only folder and images will deleted can you tell me how to call function so that when user click on yes i want to delete department and then 2nd message box will appear and if user selected yes i want to save images then function will call so save images and the delete folder and images of that department
Try following article.After deleting record show modal pop up as in article and on yes button delete images.
http://www.aspdotnet-suresh.com/2011/12/ajax-yesno-button-options-customized.html[^]
 
Share this answer
 
Comments
amitesh1989 15-Jul-13 8:17am    
hi @Pallavi Waiker i guess you didn't under stand my question yes or no is not my question anyways thanks for you reply may be it will also help me some where
Pallavi Waikar 15-Jul-13 8:28am    
I want to tell you this is also one way show confirmation box,i know this article is not for your question but can help u to show second confirm.you can also give one checkbox backup my data.In coding check for it and proceed as per value.
amitesh1989 15-Jul-13 8:46am    
Thank you @Pallavi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900