コード例 #1
0
        protected void InsertButton_Command(object sender, CommandEventArgs e)
        {
            var         controller = new RacingController();
            HiddenField raceId     = null;

            foreach (GridViewRow row in GridView1.Rows)
            {
                raceId = (HiddenField)row.FindControl("RaceID");
            }

            DropDownList memberDropDown = (DropDownList)GridView1.FooterRow.FindControl("MemberDropDown");
            DropDownList feeDropDown    = (DropDownList)GridView1.FooterRow.FindControl("FeeDropDown");
            DropDownList classDropDown  = (DropDownList)GridView1.FooterRow.FindControl("FooterClassDropDown");

            HideFooter();

            var classes = controller.CarClasses_List(int.Parse(raceId.Value));
            var members = controller.Members_List(int.Parse(raceId.Value));

            classDropDown.DataSource  = classes;
            memberDropDown.DataSource = members;

            feeDropDown.SelectedIndex = 0;

            memberDropDown.Visible = true;
            classDropDown.Visible  = true;
            feeDropDown.Visible    = true;

            Close_Results();

            classDropDown.DataBind();
            memberDropDown.DataBind();
            GridView1.EditIndex = -1;
        }
コード例 #2
0
        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
        }