//function for updating new records void Update() { //create an instance of the phone book PhoneClasses.clsPhoneCollection PhoneBook = new PhoneClasses.clsPhoneCollection(); //validate the data on the web form String Error = PhoneBook.ThisPhone.Valid(txtCapacity.Text, txtPrice.Text, txtColour.Text, txtDateAdded.Text, txtDescription.Text, txtMake.Text, txtModel.Text); //if the data is OK then add it to the object if (Error == "") { //find the record to update PhoneBook.ThisPhone.Find(PhoneID); //get the data entered by the user PhoneBook.ThisPhone.Capacity = Convert.ToInt32(txtCapacity.Text); PhoneBook.ThisPhone.Price = Convert.ToDecimal(txtPrice.Text); PhoneBook.ThisPhone.Colour = txtColour.Text; PhoneBook.ThisPhone.DateAdded = Convert.ToDateTime(txtDateAdded.Text); PhoneBook.ThisPhone.Description = txtDescription.Text; PhoneBook.ThisPhone.Make = txtMake.Text; PhoneBook.ThisPhone.Model = txtModel.Text; PhoneBook.ThisPhone.StockStatus = Convert.ToBoolean(chkStockStatus.Checked); PhoneBook.ThisPhone.Active = Convert.ToBoolean(chkActive.Checked); //update the record PhoneBook.Update(); //all done so redirect back to the main page Response.Redirect("Default.aspx"); } else { //report an error lblError.Text = "There were problems with the data entered : " + " " + Error; } }
void DisplayPhones() { //create an instance of the Phone Collection PhoneClasses.clsPhoneCollection Phones = new PhoneClasses.clsPhoneCollection(); //set the data source to the list of phones in the collection lstPhones.DataSource = Phones.PhoneList; //set the name of the primary key lstPhones.DataValueField = "PhoneID"; //set the data field to display lstPhones.DataTextField = "Make"; //bind the data to the list lstPhones.DataBind(); }