/// <summary> /// Delete a holiday from the list box /// </summary> private void btnRemove_Click(object sender, System.EventArgs e) { if(lbHolidays.SelectedIndex == -1) MessageBox.Show(LR.GetString("EditHMSelectHoliday")); else { holidays.RemoveAt(lbHolidays.SelectedIndex); this.LoadHolidayList(); } }
/// <summary> /// Cancel changes to a holiday in the collection /// </summary> /// <param name="source">The source of the event</param> /// <param name="e">The event arguments</param> protected void dgHolidays_CancelCommand(object source, DataGridCommandEventArgs e) { HolidayCollection hc = (HolidayCollection)Session["Holidays"]; // If it was a new item, remove it if (String.IsNullOrWhiteSpace(hc[e.Item.ItemIndex].Description)) { hc.RemoveAt(e.Item.ItemIndex); } dgHolidays.EditItemIndex = -1; dgHolidays.DataSource = hc; dgHolidays.DataBind(); }
/// <summary> /// Delete a holiday from the collection /// </summary> /// <param name="source">The source of the event</param> /// <param name="e">The event arguments</param> protected void dgHolidays_DeleteCommand(object source, DataGridCommandEventArgs e) { // Save changes to the edited item if it isn't the one being deleted if (dgHolidays.EditItemIndex != -1 && dgHolidays.EditItemIndex != e.Item.ItemIndex) { Page.Validate(); dgHolidays_UpdateCommand(source, new DataGridCommandEventArgs( dgHolidays.Items[dgHolidays.EditItemIndex], e.CommandSource, e)); if (!Page.IsValid) { return; } } HolidayCollection hc = (HolidayCollection)Session["Holidays"]; hc.RemoveAt(e.Item.ItemIndex); dgHolidays.EditItemIndex = -1; dgHolidays.DataSource = hc; dgHolidays.DataBind(); }