private void frmSeatVIew_Load(object sender, EventArgs e) { foreach (Control c in this.Controls) { if (c.GetType() == typeof(Button)) { if (c.Name != "btnConfirm") { c.Click += buttonClick; } } } this.FillEntity(); string bookedSeatNames = BookingRepo.GetBookedSeats(Booking.ScheduleId, Booking.JourneyDate); string[] bookedSeatNamesArray = bookedSeatNames.Split(','); // MessageBox.Show(bookedSeatNamesArray[0]); foreach (Control c in this.Controls) { if (c.GetType() == typeof(Button)) { if (c.Name != "btnConfirm") { foreach (string s in bookedSeatNamesArray) { // MessageBox.Show(c.Name); // MessageBox.Show(s); // break; if (c.Text == s) { c.Enabled = false; c.BackColor = Color.FromArgb(237, 193, 123); c.ForeColor = Color.White; } } } } } }