private void btnAddNewFault_Click(object sender, EventArgs e) { // First ensure that we persist any text changes user made to the fault list updateFaultListDataSource(); // Work out what the next order value will be (remember there may not be any (for a new profile), in which case use the increment to start us off) int newOrderValue = FAULT_ORDER_NUMBER_INCREMENT; if (CurrentProfileFaultList.Any()) { newOrderValue = CurrentProfileFaultList.Max(r => r.OrderNumber) + FAULT_ORDER_NUMBER_INCREMENT; } SafetyCheckProfileFault newFault = new SafetyCheckProfileFault(); newFault.OrderNumber = newOrderValue; CurrentProfileFaultList.Add(newFault); populateProfileFaultList(); }
/// <summary> /// Ensures the CurrentProfileFaultList reflects the data entered into the fault list table on screen /// </summary> private void updateFaultListDataSource() { for (int i = 0; i < CurrentProfileFaultList.Count; i++) { SafetyCheckProfileFault thisFault = CurrentProfileFaultList[i]; foreach (RepeaterItem item in repeaterFaultList.Items) { if (item.ItemIndex == i) { TextBox txtFaultTitle = (TextBox)item.FindControl("txtFaultTitle"); thisFault.FaultTitle = txtFaultTitle.Text; TextBox txtFaultCategory = (TextBox)item.FindControl("txtFaultCategory"); thisFault.FaultCategory = txtFaultCategory.Text; CheckBox chkIsDiscretionary = (CheckBox)item.FindControl("chkIsDiscretionary"); thisFault.IsDiscretionaryQuestion = chkIsDiscretionary.Checked; CheckBox chkHighlight = (CheckBox)item.FindControl("chkHighlight"); thisFault.Highlight = chkHighlight.Checked; // We've updated thisFault now - break out of repeater loop and move onto next fault, there can categorically be no more matches break; } } } }