// sets datasources and bind data to controls. private void Bind() { // get member var service = new Service(); var member = service.GetMember(MemberId); // set company name LabelHeader.Text = "<font color='black'>Orders for:</font> " + member.CompanyName + " (" + member.Country + ")"; GridViewOrders.DataSource = service.GetOrdersByMember(MemberId); GridViewOrders.DataBind(); }
// deletes member record protected void GridViewMembers_RowDeleting(object sender, GridViewDeleteEventArgs e) { var row = GridViewMembers.Rows[e.RowIndex]; int memberId = int.Parse(row.Cells[0].Text); var service = new Service(); // member with orders cannot be deleted var orders = service.GetOrdersByMember(memberId); if (orders.Count > 0) { string memberName = row.Cells[1].Text; LabelError.Text = "Cannot delete " + memberName + " because they have existing orders!"; } else { var member = service.GetMember(memberId); service.DeleteMember(member); Session["message"] = "Member successfully deleted"; Bind(); } }