//Cancel edit for PromoGridView protected void PromoGridView_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { PromoGridView.EditIndex = -1; PromoGridView.DataSource = BusinessLogic.Promos(); PromoGridView.DataBind(); Label7.Text = ""; }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { PromoGridView.DataSource = BusinessLogic.Promos(); PromoGridView.DataBind(); DiscountGridView.DataSource = BusinessLogic.CDiscount(); DiscountGridView.DataBind(); CategoryDDL.DataSource = BusinessLogic.Cats(); CategoryDDL.DataTextField = "Name"; CategoryDDL.DataValueField = "CategoryID"; CategoryDDL.DataBind(); } }
//Update PromoGridView with exception handling protected void UpGV1(object sender, GridViewUpdateEventArgs e) { try { GridViewRow row = PromoGridView.Rows[e.RowIndex]; string promoCode = (row.FindControl("Label1") as Label).Text; short discount = short.Parse((row.FindControl("TextBox2") as TextBox).Text); DateTime validStart = (row.FindControl("Calendar3") as Calendar).SelectedDate; int promoDuration = Convert.ToInt32((row.FindControl("TextBox4") as TextBox).Text); BusinessLogic.UpdatePromoCode(promoCode, discount, validStart, promoDuration); PromoGridView.EditIndex = -1; PromoGridView.DataSource = BusinessLogic.Promos(); PromoGridView.DataBind(); Label7.Text = "Update success!"; } catch (Exception) { Label7.Text = "Please input a valid discount amount and duration."; } }
//Edit PromoGridView protected void EdGV1(object sender, GridViewEditEventArgs e) { PromoGridView.EditIndex = e.NewEditIndex; PromoGridView.DataSource = BusinessLogic.Promos(); PromoGridView.DataBind(); }
//Unhide PromoGrid & bind data protected void PromoAmend_Click(object sender, EventArgs e) { PromoGridView.DataSource = BusinessLogic.Promos(); PromoGridView.DataBind(); PromoGridView.Visible = true; }