protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                _productId = Convert.ToInt32(RouteData.Values["ProductId"]);
                _productId = (_productId == 0) ? Convert.ToInt32(Request.QueryString["Id"]) : _productId;
                _productRepository = new ProductRepository();
                _categoryRepository = new CategoryRepository();

                _prod = _productRepository.GetProductById(_productId);
                if (!IsPostBack)
                {
                    _categoryRepository.GetAllCategories().ForEach(c => ddlCategoryId.Items.Add(new ListItem(c.CategoryName, c.CategoryId.ToString())));
                    lblProductId.Text = _prod.ProductId.ToString();
                    txtProductName.Text = _prod.ProductName;
                    ddlCategoryId.SelectedValue = _prod.CategoryId.ToString();
                    txtQuantityPerUnit.Text = _prod.QuantityPerUnit;
                    txtUnitsInStock.Text = _prod.UnitsInStock.ToString();
                    txtUnitsOnOrder.Text = _prod.UnitsOnOrder.ToString();
                    txtUnitPrice.Text = _prod.UnitPrice.ToString();
                    txtReorderLevel.Text = _prod.ReorderLevel.ToString();
                    chkDiscontinued.Checked = _prod.Discontinued;
                }
            }
            catch (InvalidOperationException)
            {
                lblMessage.Text = "Product not found.";
                lblMessage.CssClass = "Error";
            }
            catch (Exception ex)
            {
                lblMessage.Text = ex.Message;
                lblMessage.CssClass = "Error";
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     _prod = new Core.Product();
     try
     {
         _productRepository = new ProductRepository();
         _categoryRepository = new CategoryRepository();
         _supplierRepository = new SupplierRepository();
         if (!IsPostBack)
         {
             _categoryRepository.GetAllCategories().ForEach(c => ddlCategoryId.Items.Add(new ListItem(c.CategoryName, c.CategoryId.ToString())));
             _supplierRepository.GetAllSuppliers().ForEach(s => ddlSupplierId.Items.Add(new ListItem(s.CompanyName, s.SupplierId.ToString())));
         }
     }
     catch (Exception ex)
     {
         lblMessage.Text = ex.Message;
         lblMessage.CssClass = "Error";
     }
 }