protected void btn_Submit_Update_Click(object sender, EventArgs e) { Bookstore_BO bookstorebo = new Bookstore_BO(); int ProductId = Convert.ToInt32(TB_ID_Update.Text); bookstorebo.retrieveProduct(ProductId); Product prodObj = bookstorebo.retrieveProduct(ProductId); int count = 0; //validate file upload string filename; if (FileUploadImage_Update.Visible == true) { if (FileUploadImage_Update.HasFile) { string extension = System.IO.Path.GetExtension(FileUploadImage_Update.FileName); if (extension == ".jpg" || extension == ".png") { filename = FileUploadImage_Update.FileName; FileUploadImage_Update.PostedFile.SaveAs(Server.MapPath("~/Image/") + filename); string ImageURL = "~/Image/" + filename; lbl_Image_Name1.Text = ImageURL; } else { Response.Write("File has to be a jpg or png file"); } } else { sb.AppendLine("Please upload an image"); count++; } } else { filename = prodObj.ImageURL.ToString(); filename = filename.Substring(8); FileUploadImage_Update.SaveAs(Server.MapPath("~/Image/") + filename); lbl_Image_Name.Text = filename; } //validate ID Textbox if (TB_ID_Update.Text.Trim() == "") { sb.AppendLine("Please indicate product ID"); count++; } //validate Name Textbox if (TB_Name_Update.Text.Trim() == "") { sb.AppendLine("Please indicate product name"); count++; } //validate Price Textbox if (TB_Price_Update.Text == "" || TB_Price_Update.Text.All(Char.IsLetter)) { sb.AppendLine("Please amend product price"); count++; } //validate Education DDL if (Ddl_Edu_Update.SelectedItem.Text == "~Education Level~") { sb.AppendLine("Please indicate Education Level of product"); count++; } //validate Item DDL if (Ddl_Item_Update.SelectedItem.Text == "~Item Type~") { sb.AppendLine("Please indicate product type"); count++; } //validate Quantity if (TB_Quantity_Update.Text == "") { sb.AppendLine("Please enter available quantity of product"); count++; } if (count > 0) { lbl_Message1.Text = ""; TB_Error_Update.Visible = true; TB_Error_Update.Text = sb.ToString(); } else { //update database bookstorebo.updateProduct(TB_ID_Update.Text, lbl_Image_Name1.Text, TB_Name_Update.Text, Convert.ToDouble(TB_Price_Update.Text), Ddl_Edu_Update.SelectedItem.Text, Ddl_Item_Update.SelectedItem.Text, Convert.ToInt32(TB_Quantity_Update.Text)); FileUploadImage_Update.Attributes.Clear(); TB_ID_Update.Text = ""; TB_Name_Update.Text = ""; TB_Price_Update.Text = ""; Ddl_Edu_Add.SelectedIndex = -1; Ddl_Item_Add.SelectedIndex = -1; TB_Quantity_Update.Text = ""; lbl_Message1.Visible = true; lbl_Message1.Text = "Product has been updated successfully!"; TB_Error_Update.Text = ""; TB_Error_Update.Visible = false; } }