//Handle the delete button click event public void Delete_Recipes(object sender, DataGridCommandEventArgs e) { if ((e.CommandName == "Delete")) { TableCell iIdNumber2 = e.Item.Cells[0]; TableCell iIRecipename = e.Item.Cells[1]; #region Delete Recipe Image //Delete the recipe image if the recipe has an image. //Instantiate sql params object Blogic FetchData = new Blogic(); try { IDataReader dr = FetchData.GetRecipeImageFileNameForUpdate(int.Parse(iIdNumber2.Text)); dr.Read(); if (dr["RecipeImage"] != DBNull.Value) { System.IO.File.Delete(Server.MapPath(GetRecipeImage.ImagePath + dr["RecipeImage"].ToString())); } dr.Close(); } catch { } FetchData = null; #endregion //Refresh cached data Caching.PurgeCacheItems("MainCourse_RecipeCategory"); Caching.PurgeCacheItems("Ethnic_RecipeCategory"); Caching.PurgeCacheItems("RecipeCategory_SideMenu"); Caching.PurgeCacheItems("Newest_RecipesSideMenu_"); //Instantiate delete recipe object RecipeInfo DelRecipe = new RecipeInfo(); DelRecipe.ID = int.Parse(iIdNumber2.Text); //Perform delete recipe DelRecipe.Delete(); DelRecipe = null; //Redirect to confirm delete page strURLRedirect = "confirmdel.aspx?catname=" + iIRecipename.Text + "&mode=del"; Server.Transfer(strURLRedirect); } }