protected void fvAg_WFP3_Payment_ItemInserting(object sender, FormViewInsertEventArgs e) { int? i = null; int iCode = 0; FormView fv = fvAg_WFP3_Payment; DropDownList ddlPayee = fv.FindControl("ddlPayee") as DropDownList; DropDownList ddlInvoice = fv.FindControl("ddlInvoice") as DropDownList; CustomControls_AjaxCalendar tbCalPaymentDate = fv.FindControl("tbCalPaymentDate") as CustomControls_AjaxCalendar; TextBox tbCheckNumber = fv.FindControl("tbCheckNumber") as TextBox; DropDownList ddlEncumbrance = fv.FindControl("ddlEncumbrance") as DropDownList; //DropDownList ddlIsContractor = fv.FindControl("ddlIsContractor") as DropDownList; TextBox tbNote = fv.FindControl("tbNote") as TextBox; StringBuilder sb = new StringBuilder(); using (WACDataClassesDataContext wDataContext = new WACDataClassesDataContext()) { try { int?iPayee = null; if (!string.IsNullOrEmpty(ddlPayee.SelectedValue)) { iPayee = Convert.ToInt32(ddlPayee.SelectedValue); } else { sb.Append("Payee is required. "); } int?iInvoice = null; if (!string.IsNullOrEmpty(ddlInvoice.SelectedValue)) { iInvoice = Convert.ToInt32(ddlInvoice.SelectedValue); } DateTime?dtDate = tbCalPaymentDate.CalDateNullable; string sCheckNumber = WACGlobal_Methods.Format_Global_StringLengthRestriction(tbCheckNumber.Text, 16); if (string.IsNullOrEmpty(sCheckNumber)) { sb.Append("Check Number is required. "); } string sEncumbrance = null; if (!string.IsNullOrEmpty(ddlEncumbrance.SelectedValue)) { sEncumbrance = ddlEncumbrance.SelectedValue; } else { sb.Append("Encumbrance is required. "); } //string sIsContractor = null; //if (!string.IsNullOrEmpty(ddlIsContractor.SelectedValue)) sIsContractor = ddlIsContractor.SelectedValue; string sNote = WACGlobal_Methods.Format_Global_StringLengthRestriction(tbNote.Text, 400); if (string.IsNullOrEmpty(sb.ToString())) { iCode = wDataContext.form_wfp3_payment_add(FK_Wfp3, iPayee, iInvoice, dtDate, sCheckNumber, sEncumbrance, sNote, Session["userName"].ToString(), ref i); if (iCode != 0) { WACAlert.Show("Error Returned from Database. " + sb.ToString(), iCode); } else { PK_Wfp3Payment = Convert.ToInt32(i); } } else { WACAlert.Show(sb.ToString(), 0); } } catch (Exception ex) { WACAlert.Show(ex.Message, 0); } } }