protected void btnSubmit_Click(object sender, EventArgs e)
    {
        // create brand instance
        clsBrand Brand = new clsBrand();

        // retreive field values
        string BrandName     = tbName.Text;
        string TopProduct    = dropTop.SelectedValue;
        string LatestProduct = dropLatest.SelectedValue;
        string LastRestock   = cdrRestock.SelectedDate.ToString();

        // avgPrice property needs to be calculated from a mean of a brand's products

        //store Brand in session object
        // if valid passes
        string ErrorMsg = "";

        ErrorMsg = Brand.Valid(BrandName, TopProduct, LatestProduct, LastRestock);
        if (ErrorMsg == "")
        {
            // capture brand id
            Brand.BrandID = BrandID;

            Brand.BrandName     = BrandName;
            Brand.TopProduct    = int.Parse(TopProduct);
            Brand.LatestProduct = int.Parse(LatestProduct);
            Brand.LastRestock   = Convert.ToDateTime(LastRestock);
            Brand.IsListed      = cbList.Checked;

            // create a collection instance
            clsBrandCollection BrandList = new clsBrandCollection();
            //add
            if (Brand.BrandID == -1)
            {
                // set ThisBrand
                BrandList.ThisBrand = Brand;
                // add record
                BrandList.Add();
            }

            // otherwise we update
            else
            {
                BrandList.ThisBrand.Find(BrandID);
                // set ThisAddress
                BrandList.ThisBrand = Brand;
                // update
                BrandList.Update();
            }
            // redirect back to list
            Response.Redirect("BrandsList.aspx");
        }
        else
        {
            lblValidateError.Visible = true;
            lblValidateError.Text    = ErrorMsg;
        }
    }
        public void TestUpdateMethod()
        {
            // create collection instance
            clsBrandCollection AllBrands = new clsBrandCollection();
            // create test item
            clsBrand Test = new clsBrand();
            // primary key variable
            Int32 PK = 0;

            // set test item properties
            Test.BrandID       = 1;
            Test.BrandName     = "TestBrandInc";
            Test.TopProduct    = 2;
            Test.LatestProduct = 2;
            Test.LastRestock   = DateTime.Now.Date;
            Test.AvgPrice      = 0.00;
            Test.IsListed      = false;
            // set ThisBrand to be the Test object.
            AllBrands.ThisBrand = Test;
            AllBrands.Update();
            AllBrands.ThisBrand.Find(PK);
            // test that update worked
            Assert.AreEqual(AllBrands.ThisBrand, Test);
        }