// upload product's second image protected void upload2Button_Click(object sender, EventArgs e) { // proceed with uploading only if the user selected a file if (image2FileUpload.HasFile) { try { string fileName = image2FileUpload.FileName; string location = Server.MapPath("./ProductImages/") + fileName; // save image to server image2FileUpload.SaveAs(location); // update database with new product details ProductDetails pd = CatalogBLO.GetProductDetails(currentProductId); CatalogBLO.UpdateProduct(currentProductId, pd.Name, pd.Description, pd.Price.ToString(), pd.Image1FileName, fileName, pd.OnDepartmentPromotion.ToString(), pd.OnCatalogPromotion.ToString()); // reload the page Response.Redirect(Request.ApplicationPath + "/CatalogAdmin.aspx" + "?DepartmentID=" + currentDepartmentId + "&CategoryID=" + currentCategoryId + "&ProductID=" + currentProductId); } catch { statusLabel.Text = "Uploading image 2 failed"; } } }
// Update a product protected void grid_RowUpdating(object sender, GridViewUpdateEventArgs e) { // Retrieve updated data string id = grid.DataKeys[e.RowIndex].Value.ToString(); string name = ((TextBox)grid.Rows[e.RowIndex].FindControl("nameTextBox")).Text; string description = ((TextBox)grid.Rows[e.RowIndex].FindControl("descriptionTextBox")).Text; string price = ((TextBox)grid.Rows[e.RowIndex].FindControl("priceTextBox")).Text; string image1FileName = ((TextBox)grid.Rows[e.RowIndex].FindControl("image1TextBox")).Text; string image2FileName = ((TextBox)grid.Rows[e.RowIndex].FindControl("image2TextBox")).Text; string onDepartmentPromotion = ((CheckBox)grid.Rows[e.RowIndex].Cells[6].Controls[0]).Checked.ToString(); string onCatalogPromotion = ((CheckBox)grid.Rows[e.RowIndex].Cells[7].Controls[0]).Checked.ToString(); // Execute the update command bool success = CatalogBLO.UpdateProduct(id, name, description, price, image1FileName, image2FileName, onDepartmentPromotion, onCatalogPromotion); // Cancel edit mode grid.EditIndex = -1; // Display status message statusLabel.Text = success ? "Product update successful" : "Product update failed"; // Reload grid BindGrid(); }