private void AssignDataTableToCustomerNamesComboBox(DataTable dtTableCustomerNames) { CmbBxName.DataSource = dtTableCustomerNames; CmbBxName.DataTextField = "FullName"; CmbBxName.DataValueField = "Id"; CmbBxName.DataBind(); CmbBxName.Items.Insert(0, new ListItem("Please Select")); CmbBxName.SelectedIndex = 0; }
//Load Services and Stylists from DB into group checkbox and dropdownbox private void LoadServicesAndStylistForAppointmentBooking() { var PopulateDropDownListForBookingAppointments = new DataSet(); var adapterDropDownListForBookingAppointments = new SqlDataAdapter(); /*Placed connection string in a class in App_Code to improve DB connection callings*/ using (SqlConnection connection = HairStylistConnectionString.Connection()) { try { //Load Services and styliyst data from DB var command = new SqlCommand("StoredPro_PopulateDropDownListForBookingAppointments", connection); command.CommandType = CommandType.StoredProcedure; adapterDropDownListForBookingAppointments.SelectCommand = command; adapterDropDownListForBookingAppointments.Fill(PopulateDropDownListForBookingAppointments); if (PopulateDropDownListForBookingAppointments.Tables[0].Rows.Count != 0) { DDLHairLength.DataSource = PopulateDropDownListForBookingAppointments.Tables[0]; DDLHairLength.DataTextField = "HairLength"; DDLHairLength.DataValueField = "Id"; DDLHairLength.DataBind(); } else { AssignMessageToLabelWithResultFromOperation(AppConstants.LblMessage.WarningForecolor, AppConstants.LblMessage.WarningBackgroundColor, "There are no hair lenght options in Database"); } if (PopulateDropDownListForBookingAppointments.Tables[1].Rows.Count != 0) { ChkBxListServices.DataSource = PopulateDropDownListForBookingAppointments.Tables[1]; ChkBxListServices.DataTextField = "Service"; ChkBxListServices.DataValueField = "Id"; ChkBxListServices.DataBind(); } else { AssignMessageToLabelWithResultFromOperation(AppConstants.LblMessage.WarningForecolor, AppConstants.LblMessage.WarningBackgroundColor, "There are no services in Database"); } if (PopulateDropDownListForBookingAppointments.Tables[2].Rows.Count != 0) { DDLStylist.DataSource = PopulateDropDownListForBookingAppointments.Tables[2]; DDLStylist.DataTextField = "Stylist"; DDLStylist.DataValueField = "Id"; DDLStylist.DataBind(); } else { AssignMessageToLabelWithResultFromOperation(AppConstants.LblMessage.WarningForecolor, AppConstants.LblMessage.WarningBackgroundColor, "There are no stylist in Database"); } if (PopulateDropDownListForBookingAppointments.Tables[3].Rows.Count != 0) { DDLBeginTime.DataSource = PopulateDropDownListForBookingAppointments.Tables[3]; DDLBeginTime.DataTextField = "StartTime"; DDLBeginTime.DataValueField = "Id"; DDLBeginTime.DataBind(); } else { AssignMessageToLabelWithResultFromOperation(AppConstants.LblMessage.WarningForecolor, AppConstants.LblMessage.WarningBackgroundColor, "There are no service start times in Database"); } if (PopulateDropDownListForBookingAppointments.Tables[4].Rows.Count != 0) { CmbBxName.DataSource = PopulateDropDownListForBookingAppointments.Tables[4]; CmbBxName.DataTextField = "FullName"; CmbBxName.DataValueField = "Id"; CmbBxName.DataBind(); CmbBxName.Items.Insert(0, new ListItem("Please Select")); CmbBxName.SelectedIndex = 0; } else { AssignMessageToLabelWithResultFromOperation(AppConstants.LblMessage.WarningForecolor, AppConstants.LblMessage.WarningBackgroundColor, "There are no Customer Names in Database"); } command.Dispose(); } catch (System.Data.SqlClient.SqlException ex) { string str; str = "Source:" + ex.Source; str += "\n" + "Message:" + ex.Message; AssignMessageToLabelWithResultFromOperation(AppConstants.LblMessage.ErrorForecolor, AppConstants.LblMessage.ErrorBackgroundColor, str); } finally { adapterDropDownListForBookingAppointments.Dispose(); } } }