protected void fvAg_WFP3_PaymentBMP_ItemInserting(object sender, FormViewInsertEventArgs e) { int? i = null; int iCode = 0; FormView fv = fvAg_WFP3_PaymentBMP; DropDownList ddlBMP = fv.FindControl("ddlBMP") as DropDownList; DropDownList ddlPaymentStatus = fv.FindControl("ddlPaymentStatus") as DropDownList; TextBox tbAmount = fv.FindControl("tbAmount") as TextBox; TextBox tbAmountFundingAgency = fv.FindControl("tbAmountFundingAgency") as TextBox; DropDownList ddlFundingAgency = fv.FindControl("ddlFundingAgency") as DropDownList; DropDownList ddlReimbursementYN = fv.FindControl("ddlReimbursementYN") as DropDownList; TextBox tbNMCPPurchase = fv.FindControl("tbNMCPPurchase") as TextBox; DropDownList ddlBMPPractice = fv.FindControl("ddlBMPPractice") as DropDownList; StringBuilder sb = new StringBuilder(); using (WACDataClassesDataContext wDataContext = new WACDataClassesDataContext()) { try { int?iBMP = null; if (!string.IsNullOrEmpty(ddlBMP.SelectedValue)) { iBMP = Convert.ToInt32(ddlBMP.SelectedValue); } else { sb.Append("BMP is required. "); } string sPaymentStatus = null; if (!string.IsNullOrEmpty(ddlPaymentStatus.SelectedValue)) { sPaymentStatus = ddlPaymentStatus.SelectedValue; } else { sb.Append("Payment Status is required. "); } decimal?dAmount = null; try { dAmount = Convert.ToDecimal(tbAmount.Text); } catch { sb.Append("Amount is required. Data type is number (Decimal). "); } decimal?dAmountFundingAgency = null; if (!string.IsNullOrEmpty(tbAmountFundingAgency.Text)) { try { dAmountFundingAgency = Convert.ToDecimal(tbAmountFundingAgency.Text); } catch { } } string sFundingAgency = null; if (!string.IsNullOrEmpty(ddlFundingAgency.SelectedValue)) { sFundingAgency = ddlFundingAgency.SelectedValue; } string sReimbursement = ddlReimbursementYN.SelectedValue; string sNMCPPurchase = tbNMCPPurchase.Text; decimal?dBMPPracticeCode = null; if (!string.IsNullOrEmpty(ddlBMPPractice.SelectedValue)) { dBMPPracticeCode = Convert.ToDecimal(ddlBMPPractice.SelectedValue); } if (string.IsNullOrEmpty(sb.ToString())) { iCode = wDataContext.form_wfp3_paymentBMP_add(FK_Wfp3Payment, iBMP, sPaymentStatus, dAmount, dAmountFundingAgency, sFundingAgency, dBMPPracticeCode, sReimbursement, sNMCPPurchase, Session["userName"].ToString(), ref i); if (iCode != 0) { WACAlert.Show("Error Returned from Database. " + sb.ToString(), iCode); } else { PK_Wfp3PaymentBMP = Convert.ToInt32(i); } } else { WACAlert.Show(sb.ToString(), 0); } } catch (Exception ex) { WACAlert.Show(ex.Message, 0); } } }