protected void CarClassesDropDown_SelectedIndexChanged(object sender, EventArgs e) { HiddenField raceId = null; foreach (GridViewRow row in GridView1.Rows) { raceId = (HiddenField)row.FindControl("RaceID"); } DropDownList CarClassDropDown = sender as DropDownList; ListItem select = new ListItem("Select a car", "0"); GridViewRow gvr = (GridViewRow)(((Control)sender).NamingContainer); DropDownList carList = (DropDownList)gvr.FindControl("CarDropDown"); var controller = new RacingController(); var cars = controller.Cars_List(int.Parse(CarClassDropDown.SelectedValue), int.Parse(raceId.Value), 0); if (carList != null) { carList.Items.Clear(); carList.DataSource = cars; carList.Items.Add(select); carList.DataBind(); } }
protected void FooterClassDropDown_SelectedIndexChanged(object sender, EventArgs e) { HiddenField raceId = null; foreach (GridViewRow row in GridView1.Rows) { raceId = (HiddenField)row.FindControl("RaceID"); } DropDownList CarClassDropDown = sender as DropDownList; var controller = new RacingController(); var cars = controller.Cars_List(int.Parse(CarClassDropDown.SelectedValue), int.Parse(raceId.Value), 0); DropDownList carDropDown = (DropDownList)GridView1.FooterRow.FindControl("SerialDropDown"); carDropDown.DataSource = cars; carDropDown.Visible = true; carDropDown.DataBind(); }
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { RosterViewModel raceData = (RosterViewModel)e.Row.DataItem; var controller = new RacingController(); if (raceData != null) { if (raceData.RaceDetailID == 0) { LinkButton editButton = (LinkButton)e.Row.FindControl("LinkButton1"); CheckBox refund = (CheckBox)e.Row.FindControl("CheckBox1"); Label raceFee = (Label)e.Row.FindControl("RaceFeeLabel"); Label rentalFee = (Label)e.Row.FindControl("RentalFeeLabel"); refund.Visible = false; raceFee.Visible = false; rentalFee.Visible = false; editButton.Visible = false; } } #region RowDataBound Edit if (!IsPostBack) { GridView1.Visible = false; } if ((e.Row.RowState & DataControlRowState.Edit) > 0) { var classes = controller.CarClasses_List(raceData.RaceID); DropDownList carClassesDropDown = (DropDownList)e.Row.FindControl("CarClassesDropDown"); carClassesDropDown.DataSource = classes; if (raceData.CarID != null) { carClassesDropDown.SelectedValue = raceData.CarClassID.ToString(); } else { string select = "Select a car class"; carClassesDropDown.Items.Insert(0, select); } try { carClassesDropDown.DataBind(); } catch (Exception ex) { string output = string.Empty; foreach (var singleClass in classes) { output = output + singleClass.CarClassName; } MessageUserControl1.ShowInfo(ex.Message, ($"Currently Registered vehicle - '{raceData.CarClassName}' does not meet the class requirements of this race - '{output}'")); } if (raceData.CarID != null) { List <CarViewModel> cars = new List <CarViewModel>(); DropDownList carDropDown = (DropDownList)e.Row.FindControl("CarDropDown"); cars = controller.Cars_List(int.Parse(carClassesDropDown.SelectedValue), raceData.RaceID, (int)raceData.CarID); carDropDown.DataSource = cars; if (raceData.CarID != null) { carDropDown.SelectedValue = raceData.CarID.ToString(); } carDropDown.DataBind(); } TextBox refundReason = (TextBox)e.Row.FindControl("RefundTextBox") as TextBox; if (refundReason.Text.Trim().Length > 0) { refundReason.Visible = true; } Close_Results(); } #endregion }