protected void dropdownScheduleDate_SelectedIndexChanged(object sender, EventArgs e) { string dateTxt = dropdownScheduleDate.SelectedItem.Text.ToString(); DatabaseFunctions db = new DatabaseFunctions(); DataSet ds = new DataSet(); dropdownTime.Items.Clear(); ds = db.getAllTimes_CBT(dateTxt, Convert.ToInt32(ViewState["programID"])); if (ds.Tables[0].Rows.Count > 0) { //GET INGO ... string time = ds.Tables[0].Rows[0]["ScheduleTime"].ToString(); int capacity = Convert.ToInt16(ds.Tables[0].Rows[0]["Capacity"].ToString()); int Usedcapacity = Convert.ToInt16(ds.Tables[0].Rows[0]["Used"].ToString()); int available = 0; available = capacity - Usedcapacity; if (available > 0) { labelScheduleTxt.Text = dateTxt + ", " + time + " (" + available + " available)"; lblError.Visible = false; Random generator = new Random(); if (lblCbtPassword.Text == "") { int r = generator.Next(1000, 9999); lblCbtPassword.Text = r.ToString(); } } else { lblCbtPassword.Text = ""; lblError.Text = "No more space available , please choose another slot."; lblError.Visible = true; } dropdownTime.DataSource = ds.Tables[0]; dropdownTime.DataBind(); } else { labelScheduleTxt.Text = ""; dropdownTime.Items.Insert(0, new ListItem("Select Time", "")); dropdownTime.DataBind(); } }