protected void fvVenue_ItemInserting(object sender, FormViewInsertEventArgs e) { int?i = null; int iCode = 0; TextBox tbLocation = fvVenue.FindControl("tbLocation") as TextBox; DropDownList ddlPhone = fvVenue.FindControl("UC_Communication_EditInsert_Phone").FindControl("ddlNumber") as DropDownList; DropDownList ddlFax = fvVenue.FindControl("UC_Communication_EditInsert_Fax").FindControl("ddlNumber") as DropDownList; TextBox tbEmail = fvVenue.FindControl("tbEmail") as TextBox; TextBox tbNote = fvVenue.FindControl("tbNote") as TextBox; StringBuilder sb = new StringBuilder(); using (WACDataClassesDataContext wDataContext = new WACDataClassesDataContext()) { try { string sLocation = null; if (!string.IsNullOrEmpty(tbLocation.Text)) { sLocation = WACGlobal_Methods.Format_Global_StringLengthRestriction(tbLocation.Text, 48).Trim(); } else { sb.Append("Location is required. "); } int?iPhone = null; if (!string.IsNullOrEmpty(ddlPhone.SelectedValue)) { iPhone = Convert.ToInt32(ddlPhone.SelectedValue); } int?iFax = null; if (!string.IsNullOrEmpty(ddlFax.SelectedValue)) { iFax = Convert.ToInt32(ddlFax.SelectedValue); } string sEmail = WACGlobal_Methods.Format_Global_StringLengthRestriction(tbEmail.Text, 48).Trim(); string sNote = WACGlobal_Methods.Format_Global_StringLengthRestriction(tbNote.Text, 255).Trim(); if (string.IsNullOrEmpty(sb.ToString())) { iCode = wDataContext.eventVenue_add(sLocation, iPhone, iFax, sEmail, sNote, Session["userName"].ToString(), ref i); if (iCode == 0) { fvVenue.ChangeMode(FormViewMode.ReadOnly); BindVenue(Convert.ToInt32(i)); } else { WACAlert.Show("Error Returned from Database.", iCode); } } else { WACAlert.Show(sb.ToString(), 0); } } catch (Exception ex) { WACAlert.Show("Error: " + ex.Message, 0); } } }