示例#1
0
        public MultipleSelectControl(MultipleSelect item, RepeatDirection direction)
        {
            this.item = item;

            l = new Label();
            l.Text = item.Title;
            l.CssClass = "label";
            l.AssociatedControlID = item.Name;
            this.Controls.Add(l);

            list = new CheckBoxList();
            list.RepeatDirection = direction;
            list.ID = item.Name;
            list.CssClass = "alternatives";
            list.DataSource = item.GetChildren();
            list.DataTextField = "Title";
            list.DataValueField = "ID";
            list.DataBind();
            this.Controls.Add(list);

            if (item.Required)
            {
                cv = new CustomValidator { Display = ValidatorDisplay.Dynamic, Text = "*" };
                cv.ErrorMessage = item.Title + " is required";
                cv.ServerValidate += (s, a) => a.IsValid = !string.IsNullOrEmpty(AnswerText);
                cv.ValidationGroup = "Form";
                this.Controls.Add(cv);
            }
        }
示例#2
0
 public void setCheckBoxList(CheckBoxList chl, DataSet ds, string display, string value)
 {
     chl.DataSource = ds;
     chl.DataTextField = display;
     chl.DataValueField = value;
     chl.DataBind();
 }
示例#3
0
    /// <summary>
    ///		This method binds a drop down list to a given DataSet
    /// </summary>
    /// <param name="textField">
    ///		Field from the datasource to use for the option text
    /// </param>
    /// <param name="valueField">
    ///		Field from the datasource to use for the option value
    /// </param>
    /// <param name="dsDataSet">
    ///		DataSource
    /// </param>
    /// <param name="dropDownListID">
    ///		Name of the Drop down list
    /// </param>
    public void BindCheckList(string textField, string valueField, DataSet dsDataSet, System.Web.UI.WebControls.CheckBoxList checkBoxListID)
    {
        try
        {
            checkBoxListID.DataSource = dsDataSet.Tables[0];
            //set DataTextField property only if it is not null
            if (null != textField)
            {
                checkBoxListID.DataTextField = textField;
            }
            //set DataValueField property only if it is not null
            if (null != valueField)
            {
                checkBoxListID.DataValueField = valueField;
            }
            checkBoxListID.DataBind();
        }

        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
        }
    }
示例#4
0
        protected override void OnPreRender(EventArgs e)
        {
            if (!IsPostBack)
            {
                string[]  colAlias  = SampleConstants.BoundDataColumns;
                ArrayList ThemeList = new ArrayList();
                ThemesAndModifiers.FillThemeNames(ThemeList);

                DropDownList1.Items.Clear();
                DropDownList1.DataSource = ThemeList;
                DropDownList1.DataBind();

                // Prepare CheckBoxes, RadioButtons and note label contents.
                CheckBoxList1.DataSource = colAlias;
                CheckBoxList1.DataBind();
                CheckBoxList1.Visible = this.IsCheckBoxListVisible(ThemeList[0] as string);

                RadioButtonList1.DataSource = colAlias;
                RadioButtonList1.DataBind();
                RadioButtonList1.Visible = this.IsRadioButtonListVisible(ThemeList[0] as string);

                Label2.Visible = this.IsNoteLabelVisible(ThemeList[0] as string);
                Label2.Text    = "Please select two columns from below checkboxes.";

                DropDownList1.Items.Clear();
                DropDownList1.DataSource = ThemeList;
                DropDownList1.DataBind();
            }
        }
示例#5
0
 public static void ChkListFill(ref CheckBoxList chkl, object list)
 {
     chkl.DataTextField = listDefaultDataTextField;
     chkl.DataValueField = listDefaultDataValueField;
     chkl.DataSource = list;
     chkl.DataBind();
 }
示例#6
0
        public bool LlenarGrid_Web(System.Web.UI.WebControls.CheckBoxList Generico)
        {
            if (!Validar())
            {
                return(false);
            }
            clsConexionMySQLDB objConexionBD = new clsConexionMySQLDB();

            objConexionBD.SQL         = strSQL;
            objConexionBD.NombreTabla = strNombreTabla;

            if (!objConexionBD.LlenarDataSet(false))
            {
                strError = objConexionBD.Error;
                objConexionBD.CerrarConexion();
                objConexionBD = null;
                return(false);
            }
            Generico.DataSource     = objConexionBD.MiDataSet.Tables[strNombreTabla];
            Generico.DataTextField  = strColumnaTexto;
            Generico.DataValueField = strColumnaValor;
            Generico.DataBind();
            objConexionBD.CerrarConexion();
            objConexionBD = null;
            return(true);
        }
示例#7
0
 /// <summary>
 /// 绑定CheckBoxList,value为初始选中值
 /// </summary>
 /// <param name="ck">CheckBoxList</param>
 /// <param name="ds">dataset</param>
 /// <param name="textField">文本字段</param>
 /// <param name="valueField">值字段</param>
 /// <param name="value">以,隔开的字符串,默认选中值</param>
 public static void BindCheckBoxList(System.Web.UI.WebControls.CheckBoxList ck, DataSet ds, string textField, string valueField, string value)
 {
     if (null != ds && ds.Tables[0].Rows.Count > 0)
     {
         ck.DataSource     = ds;
         ck.DataTextField  = textField;
         ck.DataValueField = valueField;
         ck.DataBind();
     }
     if (!string.IsNullOrEmpty(value))
     {
         string[] v = value.Split(',');
         for (int i = 0; i < v.Length; i++)
         {
             for (int j = 0; j < ck.Items.Count; j++)
             {
                 if (v[i] == ck.Items[j].Value)
                 {
                     ck.Items[j].Selected = true;
                     break;
                 }
             }
         }
     }
 }
示例#8
0
 public void FillCheckBoxList(CheckBoxList chk, DataTable mydt, string textField, string valueFeild)
 {
     chk.DataSource = mydt;
     chk.DataValueField = valueFeild;
     chk.DataTextField = textField;
     chk.DataBind();
     chk.Items.Insert(0, new ListItem { Value = "0", Text = "All", Selected = false });
 }
 public static void populateCheckbox(CheckBoxList element)
 {
     element.DataSource = controller().index();
     element.AppendDataBoundItems = true;
     element.DataTextField = "nom_disc";
     element.DataValueField = "id";
     element.DataBind();
 }
示例#10
0
 public static void populate(CheckBoxList element, int id_equipe)
 {
     element.DataSource = controller().find_by_equipe(id_equipe);
     element.AppendDataBoundItems = true;
     element.DataTextField = "nome";
     element.DataValueField = "id";
     element.DataBind();
 }
 private void BindRights()
 {
     RightsCheckBoxList.DataSource     = new Roles().GetSecurityRightList();
     RightsCheckBoxList.DataMember     = "SecurityRights";
     RightsCheckBoxList.DataTextField  = "description";
     RightsCheckBoxList.DataValueField = "SecurityRightId";
     RightsCheckBoxList.DataBind();
     ((PageBase)Page).TranslateListControl(RightsCheckBoxList);
 }
示例#12
0
        public void FillCheckBoxList(ref CheckBoxList objchkList, string strQuery, string strTextField, string strValueField, string strOrderBy, string strQueryCondition = "")
        {
            dsCommon = new DataSet();
            dsCommon = CrystalConnection.CreateDatasetWithoutTransaction(strQuery + " " + strQueryCondition + " " + strOrderBy);

            objchkList.DataTextField = strTextField;
            objchkList.DataValueField = strValueField;
            objchkList.DataSource = dsCommon.Tables[0].DefaultView;
            objchkList.DataBind();
        }
示例#13
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here
            if (!IsPostBack)
            {
                DataTable            dt1 = new DataTable("Employee"), dt2 = new DataTable("Department");
                DataColumnCollection dc1 = dt1.Columns, dc2 = dt2.Columns;
                dc1.Add("EmployeeID", typeof(int));
                dc1.Add("Name", typeof(string));
                dc1.Add("DepartmentID", typeof(int));
                dc2.Add("DepartmentID", typeof(int));
                dc2.Add("Name", typeof(string));

                //dt1.PrimaryKey=new DataColumn[] {dc1["EmployeeID"]};
                //dt2.PrimaryKey=new DataColumn[] {dc2["DepartmentID"]};
                dt2.DisplayExpression = dt1.DisplayExpression = "DepartmentID";
                DataRow dr = dt1.NewRow();
                dr.ItemArray = new object[] { 1, "rags", 10 };
                dt1.Rows.Add(dr);
                dr           = dt1.NewRow();
                dr.ItemArray = new object[] { 2, "rags1", 10 };
                dt1.Rows.Add(dr);
                dr           = dt1.NewRow();
                dr.ItemArray = new object[] { 3, "rags3", 10 };
                dt1.Rows.Add(dr);
                dr           = dt1.NewRow();
                dr.ItemArray = new object[] { 5, "rags5", 11 };
                dt1.Rows.Add(dr);
                dr           = dt1.NewRow();
                dr.ItemArray = new object[] { 4, "rags4", 11 };
                dt1.Rows.Add(dr);
                dt1.AcceptChanges();
                dr           = dt2.NewRow();
                dr.ItemArray = new object[] { 10, "dept1" };
                dt2.Rows.Add(dr);
                dr           = dt2.NewRow();
                dr.ItemArray = new object[] { 11, "dept2" };
                dt2.Rows.Add(dr);
                dr           = dt2.NewRow();
                dr.ItemArray = new object[] { 12, "dept3" };
                dt2.Rows.Add(dr);
                dt2.AcceptChanges();
                DataSet dst = new DataSet("CompanyDS");
                dst.Tables.AddRange(new DataTable[] { dt1, dt2 });
                dst.Relations.Add("DeptEmp", dc2["DepartmentID"], dc1["DepartmentID"]);
                DropDownList1.DataSource     = dt2;
                DropDownList1.DataTextField  = "Name";
                DropDownList1.DataValueField = "DepartmentID";
                DropDownList1.DataBind();
                //strl.Attributes.Add("onclick","alert()");
                Session["dst"] = dst;
                //dst.WriteXml(Server.MapPath("XML/xmlfile1.xml"),XmlWriteMode.WriteSchema);
                BindGrid();
            }
        }
示例#14
0
        /// <summary>
        /// CheckBoxList快速绑定

        /// </summary>
        /// <param name="ddlControls">cbl控件</param>
        /// <param name="dt">DataTable表</param>
        /// <param name="strName">要绑定的Text列</param>
        /// <param name="strValue">要绑定的Value列</param>
        public static void CheckBoxListBind(System.Web.UI.WebControls.CheckBoxList ddlControls, DataTable dt, string strName, string strValue, bool isDisplay)
        {
            ddlControls.DataSource     = dt;
            ddlControls.DataTextField  = strName;
            ddlControls.DataValueField = strValue;
            ddlControls.DataBind();
            if (isDisplay)
            {
                dt.Dispose();
            }
        }
示例#15
0
    public void FillchkListBox(System.Web.UI.WebControls.CheckBoxList lst, ref tblAttributes objtblAttr, bool blnAutoPostBack, int intSelectedId)
    {
        SqlDataReader objReader = null;

        try
        {
            DBConnectionOpenDynamic(0);
            FillDataReader obj = new FillDataReader();
            if ((objReader != null))
            {
                if (objReader.IsClosed == false)
                {
                    objReader.Close();
                }
            }
            objReader        = obj.fn_FillDataReader(ref objtblAttr, con);
            lst.AutoPostBack = blnAutoPostBack;
            if (intSelectedId != 0)
            {
                lst.SelectedValue = Convert.ToString(intSelectedId);
            }
            lst.DataSource    = objReader;
            lst.RepeatColumns = objtblAttr.intColumn;
            //lst.RepeatDirection = objtblAttr.strRepeateDirection;
            lst.DataTextField  = objtblAttr.strDisplayField;
            lst.DataValueField = objtblAttr.strValueField;
            lst.DataBind();
        }
        catch (Exception ex)
        {
            if (objtblAttr.strProc != "sp_getIUDErrorDetails")
            {
                saveErrorDetails(objtblAttr.strQuery, objtblAttr.strProc, returnStringFromArr(objtblAttr.strOutputStringArr), HttpContext.Current.Request.RawUrl, "CLB", ex.Message);
            }
        }
        finally
        {
            if (con != null)
            {
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
            }
            if (objReader != null)
            {
                if (objReader.IsClosed == false)
                {
                    objReader.Close();
                }
            }
        }
    }
        /// <summary>
        /// CheckBoxListBind邦定
        /// </summary>
        /// <param name="chklControl">CheckBoxList控件</param>
        /// <param name="strTableName">表名</param>
        /// <param name="strText">显示的字段</param>
        /// <param name="strValue">值字段</param>
        /// <param name="strWhere">查询条件</param>
        public static void CheckBoxListBind(System.Web.UI.WebControls.CheckBoxList chklControl, string strTableName, string strText, string strValue, string strWhere)
        {
            string  strSql  = "SELECT * FROM " + strTableName + " Where " + strWhere;
            DataSet dstTemp = new DataSet();

            dstTemp = DbHelperSQL.Query(strSql);

            chklControl.DataSource     = dstTemp.Tables[0];
            chklControl.DataTextField  = strText;
            chklControl.DataValueField = strValue;
            chklControl.DataBind();
        }
示例#17
0
 /// <summary>
 /// Load All Sizes in CheckBox Collections.
 /// </summary>
 public static void AllSizes(CheckBoxList SizeschkBxs, List<StyleSize> sizes=null)
 {
     List<Size> sizes_list = SM.Sizes();
     if (sizes == null)
     {
         SizeschkBxs.DataSource = SM.Sizes();
         SizeschkBxs.DataValueField = "SizeCode";
         SizeschkBxs.DataTextField = "SizeDescription";
         SizeschkBxs.DataBind();
     }
     else
     {
         var results = (from size in sizes_list
                        join s_size in sizes on size.SizeCode  equals s_size.SizeCode
                        select size).ToList<Size>();
         SizeschkBxs.DataSource = sizes_list.Except(results);
         SizeschkBxs.DataValueField = "SizeCode";
         SizeschkBxs.DataTextField = "SizeDescription";
         SizeschkBxs.DataBind();
     }
 }
示例#18
0
        private void BindData()
        {
            DataSet emailDataSet = Utilites.StaticMethods.GetUsersNameAndDept();

            emailList.DataSource     = emailDataSet;
            emailList.DataTextField  = "Name";
            emailList.DataValueField = "UserID";
            emailList.DataBind();
            this.emailHistoryList.DataSource = Utilites.Email.GetEmailHistory(_IncidentId);

            this.emailHistoryList.DataBind();
        }
 public static void FillDataToCheckboxList(CheckBoxList control, string table, string dataTextField, string dataValueField)
 {
     OpenData();
     string strCommand = "SELECT " + dataTextField + ", " + dataValueField + " FROM " + table;
     da = new SqlDataAdapter(strCommand, con);
     ds = new DataSet();
     da.Fill(ds, strCommand);
     control.DataSource = ds;
     control.DataTextField = dataTextField;
     control.DataValueField = dataValueField;
     control.DataBind();
     CloseData();
 }
示例#20
0
        /// <summary>
        /// Load All Colors in CheckBox Collections.
        /// </summary>
        public static void AllColors(CheckBoxList ColorchkBx, List<StyleColor> colors= null)
        {
            List<Color> color_list = CM.Colors();
            if (colors == null)
            {
                ColorchkBx.DataSource = CM.Colors();
                ColorchkBx.DataValueField = "ColorCode";
                ColorchkBx.DataTextField = "ColorDescription";
                ColorchkBx.DataBind();
            }
            else
            {
                var results = (from color in color_list
                             join s_color in colors on color.ColorCode equals s_color.ColorCode
                             select color).ToList<Color>();

                ColorchkBx.DataSource = color_list.Except(results);
                ColorchkBx.DataValueField = "ColorCode";
                ColorchkBx.DataTextField = "ColorDescription";
                ColorchkBx.DataBind();
            }
        }
 public static void FillDataToCheckBoxList(CheckBoxList control, string table, string dataTextField, string dataValueField)
 {
     opendata();
     string strCommand = "SELECT " + dataTextField + ", " + dataValueField + " FROM " + table;
     sqladapter = new SqlDataAdapter(strCommand, sqlconn);
     mydata = new DataSet();
     sqladapter.Fill(mydata, strCommand);
     control.DataSource = mydata;
     control.DataTextField = dataTextField;
     control.DataValueField = dataValueField;
     control.DataBind();
     closedata();
 }
示例#22
0
        protected void FillFilterListBox(CheckBoxList listBox, DataView dataView, String member)
        {
            var values = (from DataRowView n in dataView
                          let v = n[member]
                                  orderby v
                                  select v).Distinct().ToList();

            listBox.DataSource = values;
            listBox.DataBind();

            var selValues = GetListBoxSelectedValues(listBox).ToHashSet();

            foreach (ListItem listItem in listBox.Items)
            {
                listItem.Selected = selValues.Contains(listItem.Value);
            }
        }
示例#23
0
//		private void FillOperRbl()
//		{
//			try
//			{
//				DataTable dtAllOper = Helper.Query("select * from tbOper");
//
//				rblOper.DataSource = dtAllOper;
//				rblOper.DataTextField = "cnvcOperName";
//				rblOper.DataValueField = "cnvcOperID";
//
//				rblOper.DataBind();
//			}
//			catch (BusinessException bex)
//			{
//				Popup(bex.Message);
//			}
//
//		}

        private void FillFunctionCbl()
        {
            try
            {
                DataTable dtFunc = (DataTable)Application[ConstApp.A_FUNC];                //Helper.Query("select * from tbFunc");

                cblFunctionList.DataSource     = dtFunc;
                cblFunctionList.DataTextField  = "cnvcFuncName";
                cblFunctionList.DataValueField = "cnvcFuncCode";

                cblFunctionList.DataBind();
            }
            catch (BusinessException bex)
            {
                Popup(bex.Message);
            }
        }
示例#24
0
        public static void Concessionaria(CheckBoxList ck)
        {
            try
            {
                ck.DataSource = CRB.BOSS.Autenticacao.Concessionaria.Concessionaria.CarregarConcessionariasAutenticadas();
                ck.DataValueField = "ID";
                ck.DataTextField = "Nome";
                ck.DataBind();

                CRB.BOSS.Auditoria.Log.Log.Salvar("Carregar CheckBoxList de Concessionaria", CRB.BOSS.Auditoria.Log.InformacoesLog.Information, CRB.BOSS.Autenticacao.Modulo.Modulo.Funcionalidade, CRB.BOSS.Autenticacao.Modulo.Modulo.Atual);
            }
            catch (Exception ex)
            {
                CRB.BOSS.Auditoria.Log.Log.Salvar(ex.Message, CRB.BOSS.Auditoria.Log.InformacoesLog.Information, CRB.BOSS.Autenticacao.Modulo.Modulo.Funcionalidade, CRB.BOSS.Autenticacao.Modulo.Modulo.Atual);

                throw ex;
            }
        }
示例#25
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            // The first time in
            if (Session.IsNewSession)
            {
                //******************************************************************************//
                //*   You need to follow below lines in your own application in order to       *//
                //*   save state manually.                                                     *//
                //*   You don't need this state manager if the "MapInfo.Engine.Session.State"  *//
                //*   in the web.config is not set to "Manual"                                 *//
                //******************************************************************************//
                if (AppStateManager.IsManualState())
                {
                    AppStateManager stateManager = new AppStateManager();
                    // tell the state manager which map alias you want to use.
                    // You could also add your own key/value pairs, the value should be serializable.
                    stateManager.ParamsDictionary[AppStateManager.ActiveMapAliasKey] = this.MapControl1.MapAlias;
                    // Put state manager into HttpSession, so we could get it later on.
                    AppStateManager.PutStateManagerInSession(stateManager);
                }

                // Initialize map setting.
                InitState();

                // WarningLabel is invisible in the init state
                WarningLabel.Visible = false;
            }

            // Restore state.
            if (MapInfo.WebControls.StateManager.IsManualState())
            {
                MapInfo.WebControls.StateManager.GetStateManagerFromSession().RestoreState();
            }

            if (!IsPostBack)
            {
                // DataBind named connection names to RadioButtonList.
                CheckBoxList1.DataSource = MapInfo.Engine.Session.Current.Catalog.NamedConnections.Keys;
                CheckBoxList1.DataBind();

                // Populate aliases of opened tables to Repeater web control.
                BindOpenedTablesAliasToRepeater();
            }
        }
示例#26
0
        protected void RebindModelDescriptions()
        {
            string country_owner = SessionHandler.MappingSelectedCountryOwner;
            string country_rent  = SessionHandler.MappingSelectedCountryRent;
            string start_date    = SessionHandler.MappingSelectedStartDate;

            System.Web.UI.WebControls.CheckBoxList checkBoxListModelDesc = (System.Web.UI.WebControls.CheckBoxList) this.ModelDescription.FindControl("CheckBoxListPopUp");
            checkBoxListModelDesc.DataTextField  = "ModelDescription";
            checkBoxListModelDesc.DataValueField = "ModelDescription";
            checkBoxListModelDesc.Items.Clear();
            checkBoxListModelDesc.DataSource = MappingsVehiclesLease.SelectModelsDescription(country_owner, country_rent, start_date);
            checkBoxListModelDesc.DataBind();
            foreach (ListItem item in checkBoxListModelDesc.Items)
            {
                item.Selected = false;
            }
            //Load the check box list settings
            this.ModelDescription.LoadCheckBoxList();
        }
示例#27
0
        /// <summary>
        /// 将查询的结果绑定到指定的DropDownList中,
        /// </summary>
        /// <param name="strText">DropDownList中前台列表中显示的文字所对应的字段</param>
        /// <param name="strValue">DropDownList中后台对应的值所对应的字段</param>
        /// <param name="strSqlPra">获得绑定内容的查询语句</param>
        /// <param name="drop_TobeBundled">待绑定的DropDownList控件</param>
        /// <returns>返回绑定结果,成功则为true</returns>
        public static bool BindList(string strText, string strValue, string strSqlPra, System.Web.UI.WebControls.CheckBoxList drop_TobeBundled)
        {
            try
            {
                string strSql = strSqlPra;

                MyDataOp mdo = new MyDataOp(strSql);
                DataSet  ds  = mdo.CreateDataSet();
                drop_TobeBundled.DataTextField  = strText;
                drop_TobeBundled.DataValueField = strValue;
                drop_TobeBundled.DataSource     = ds;
                drop_TobeBundled.DataBind();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
示例#28
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="channelID"></param>
        /// <param name="cblStation"></param>
        /// <param name="deviceTypes"></param>
        /// <param name="isSelected"></param>
        public static void StationOfChannelBind(int channelID, CheckBoxList cblStation, string[] deviceTypes, bool isSelected)
        {
            ChannelClass ch = ChannelFactory.CreateChannel(channelID);
            if (ch != null)
            {
                StationCollection sts = ch.StationCollection.GetStationCollection(deviceTypes);

                ListItemCollection stationList = GetStationListItemCollection(sts);
                cblStation.DataTextField = "Text";
                cblStation.DataValueField = "Value";
                cblStation.DataSource = stationList;
                cblStation.DataBind();

                foreach (ListItem stitem in cblStation.Items)
                {
                    stitem.Selected = isSelected;
                }
            }
        }
示例#29
0
        private void RefreshUmfragenListe()
        {
            // Umfragen des eingeloggten Benutzers abrufen:
            // Daten vorbereiten
            SqlParameter pUserID = DataAccessUmfragen.Paramr_userID;

            pUserID.Value = SessionContainer.ReadFromSession(this).User.UserID;
            DataParameters parameters = new DataParameters();

            parameters.Add(pUserID);
            DSUmfragen ds = m_daUmfragen.Select(parameters);

            // in der Checkboxliste darstellen
            m_chblUmfragenListe.DataSource = ds.umfragen;
            // den Titel der Umfrage neben der Checkbox anzeigen
            m_chblUmfragenListe.DataTextField = ds.umfragen.Columns["Titel"].ToString();
            // die UmfrageID als Value mitgeben, um zum Löschen oder Bearbeiten wieder an den Datensatz zu kommen
            m_chblUmfragenListe.DataValueField = ds.umfragen.Columns["UmfrageID"].ToString();
            m_chblUmfragenListe.DataBind();
            // wenn keine Datensätze gefunden wurden, sollen die Umfragenliste und die
            // dazugehörigen Buttons nicht sichtbar sein
            m_tblUmfragenListe.Visible = (ds.umfragen.Rows.Count > 0);
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!this.IsPostBack)
            {
                Cache.Remove("Titles");

                DataSet dsPubs;
                if (Cache["Titles"] == null)
                {
                    dsPubs = RetrieveData();
                    Cache.Insert("Titles", dsPubs, null, DateTime.MaxValue, TimeSpan.FromMinutes(2));
                    lblCacheStatus.Text = "Created and added to cache.";
                }
                else
                {
                    dsPubs = (DataSet)Cache["Titles"];
                    lblCacheStatus.Text = "Retrieved from cache.";
                }
                chkColumns.DataSource = dsPubs.Tables[0].Columns;
                chkColumns.DataMember = "Item";
                chkColumns.DataBind();
            }
        }
        private void FillFunctionCbl()
        {
            try
            {
                DataTable dtBSFunction = ReportQueryFacade.CommonQuery("select * from tbFunc where cnvcFuncType='BS' order by cnvcFuncName");
                DataTable dtCSFunction = ReportQueryFacade.CommonQuery("select * from tbFunc where cnvcFuncType='CS' order by cnvcFuncName");

                cblFunctionList.DataSource     = dtBSFunction;
                cblFunctionList.DataTextField  = "cnvcFuncName";
                cblFunctionList.DataValueField = "cnvcFuncAddress";

                cblFunctionList.DataBind();

                cblCSFunctionList.DataSource     = dtCSFunction;
                cblCSFunctionList.DataTextField  = "cnvcFuncName";
                cblCSFunctionList.DataValueField = "cnvcFuncAddress";

                cblCSFunctionList.DataBind();
            }
            catch (BusinessException bex)
            {
                Popup(bex.Message);
            }
        }
示例#32
0
 public void LoadCombo(DataTable dt, CheckBoxList ddl)
 {
     ddl.DataSource = dt;
     if (dt != null)
     {
         ddl.DataValueField = dt.Columns[0].ColumnName;
         ddl.DataTextField = dt.Columns[1].ColumnName;
     }
     ddl.DataBind();
 }
示例#33
0
        /// <summary>
        /// Lägger till varje fråga i paneln och visar om man har svarat rätt eller fel. 
        /// </summary>
        /// <param name="queID"></param>
        /// <param name="ttID"></param>
        private void fillData(string queID, string ttID)
        {
            clsFillQuestion quest = new clsFillQuestion();
            Tuple<DataTable, string, int, string, string> Que = quest.readXML(queID, ttID);
            DataTable dt = Que.Item1;

            Label lbN = new Label();
            string img = "";
            if (Que.Item5 != null)
            {
                img = "<img src='pictures/" + Que.Item5 + "' style='height: 150px; width: 150px;'alt='bilden' />";
            }
            lbN.ID = "QUEST_" + queID;
            lbN.Text = "<h5>" + Que.Item2 + "</h5> " + img  + "<br />";

            panData.Controls.Add(lbN);
            int many = 0;
            for (int i = 0; i < Que.Item1.Rows.Count; i++)
            {
                if (Que.Item1.Rows[i]["answ"].ToString().ToUpper() == "TRUE")
                {
                    many += 1;
                }
            }
            if (many > 1) //Om det finns flera valmöjligheter så sätter vi ut en checkboxliist
            {
                CheckBoxList li = new CheckBoxList();
                li.ID = queID;
                li.DataTextField = "name";
                li.DataValueField = "id";
                li.DataSource = dt;
                li.DataBind();
                li.Enabled = false;
                for (int i = 0; i < dt.Rows.Count; i++)  //KRyssar i de som redan användaren har kryssat i
                {
                    int val = 0;
                    if (dt.Rows[i]["sel"].ToString().ToUpper() == "TRUE")
                    {
                        if (int.TryParse(dt.Rows[i]["id"].ToString(), out val))
                        {
                            li.Items.FindByValue(val.ToString()).Selected = true; //Sätter alla som finns till true så att den kan vara multippella
                            li.Items.FindByValue(val.ToString()).Attributes.Add("style", "border: 2px solid red;");
                        }
                        val = 0;
                    }
                    if (dt.Rows[i]["answ"].ToString().ToUpper() == "TRUE")
                    {
                        if (int.TryParse(dt.Rows[i]["id"].ToString(), out val))
                        {
                            li.Items.FindByValue(val.ToString()).Attributes.Add("style", "border: 2px solid green;"); //= System.Drawing.Color.Green; //Sätter alla som finns till true så att den kan vara multippella
                        }
                        val = 0;
                    }
                }
                panData.Controls.Add(li);
            }
            else
            {
                RadioButtonList li = new RadioButtonList();
                li.ID = queID;
                li.DataTextField = "name";
                li.DataValueField = "id";
                li.DataSource = Que.Item1;
                li.DataBind();
                li.Enabled = false;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    int val = 0;
                    if (dt.Rows[i]["sel"].ToString().ToUpper() == "TRUE")
                    {
                        if (int.TryParse(dt.Rows[i]["id"].ToString(), out val))
                        {
                            li.SelectedValue = val.ToString();
                            li.Items.FindByValue(val.ToString()).Attributes.Add("style", "border: 2px solid red;");
                        }
                    }
                    if (dt.Rows[i]["answ"].ToString().ToUpper() == "TRUE") //Om man vill kolla på frågorna igen så markeras den grön om det är okej
                    {
                        if (int.TryParse(dt.Rows[i]["id"].ToString(), out val))
                        {
                            li.Items.FindByValue(val.ToString()).Attributes.Add("style", "border: 2px solid green;");
                        }
                    }
                }
                panData.Controls.Add(li);
            }
        }
示例#34
0
        public void LoadCheckBox(DataSet ds, CheckBoxList chk)
        {
            //  ListItem li = new ListItem();

            chk.DataSource = ds;
            if (ds != null)
            {
                chk.DataValueField = ds.Tables[0].Columns[0].ColumnName;
                chk.DataTextField = ds.Tables[0].Columns[1].ColumnName;
            }
            chk.DataSource = ds.Tables[0];
            chk.DataBind();
            // chk.Items.Insert(1, li);
        }
示例#35
0
 private void BindPermissions()
 {
     daPermission.Fill(sm1.权限模块);
     SelectPermission.DataBind();
 }
示例#36
0
 /// <summary>
 /// 绑定CheckBoxList
 /// </summary>
 /// <param name="strSql"></param>
 /// <param name="fieldName"></param>
 /// <param name="valueNmae"></param>
 /// <param name="rbtName"></param>
 protected void GetFromData(string strSql, string fieldName, string valueNmae, CheckBoxList cblName)
 {
     Database db = DatabaseFactory.CreateDatabase(CawConnStr);
     DataView dvReturn = db.ExecuteDataView(CommandType.Text, strSql);
     cblName.DataSource = dvReturn;
     cblName.DataTextField = fieldName;
     cblName.DataValueField = valueNmae;
     cblName.DataBind();
 }
示例#37
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here
            if (!IsPostBack)
            {
                string strLoginID  = this.Request.QueryString["id"].ToString();
                string strOperName = this.Request.QueryString["name"].ToString();
                string strFuncType = this.Request.QueryString["FuncType"].ToString();
                this.txtCS.Text = strFuncType;
                if (strLoginID == null || strLoginID == "" || strOperName == null || strOperName == "" || strFuncType == null || strFuncType == "")
                {
                    this.SetErrorMsgPageBydirHistory("所选操作员登录ID错误,请重试!");
                    return;
                }
                else
                {
                    this.lblOperID.Text   = strLoginID;
                    this.lblOperName.Text = strOperName;

                    Hashtable htapp   = (Hashtable)Application["appconf"];
                    string    strcons = (string)htapp["cons"];
                    m1 = new BusiComm.Manager(strcons);
                    //if(strFuncType="BS")
                    DataSet   dsout      = m1.GetFuncList(strLoginID, strFuncType);
                    DataTable dtfunclist = dsout.Tables["funclist"];
                    DataTable dtoperfunc = dsout.Tables["operfunc"];
                    if (dtfunclist != null)
                    {
                        cblFunc.DataSource     = dtfunclist;
                        cblFunc.DataTextField  = "cnvcFuncName";
                        cblFunc.DataValueField = "cnvcFuncAddress";

                        cblFunc.DataBind();

                        foreach (ListItem liFunctionList in this.cblFunc.Items)
                        {
                            if (liFunctionList.Selected)
                            {
                                liFunctionList.Selected = false;
                            }
                        }
                        {
                            foreach (ListItem liFunctionList in this.cblFunc.Items)
                            {
                                if (dtoperfunc != null && dtoperfunc.Rows.Count > 0)
                                {
                                    foreach (DataRow drOperFunc in dtoperfunc.Rows)
                                    {
                                        if (drOperFunc["vcFuncName"].ToString().Equals(liFunctionList.Text))
                                        {
                                            liFunctionList.Selected = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        this.SetErrorMsgPageBydirHistory("获取功能列表错误!");
                        return;
                    }
                }
            }
        }
示例#38
0
		public void AppendEditViewFieldsEdit(string sEDIT_NAME, HtmlTable tbl, DataRowView rdr, ref int nRowIndex, string sFIELD_WIDTH, Hashtable hashIncludedFields, bool bIsPostBack)
		{
			DataTable dtFields = SplendidCache.EditViewFields(sEDIT_NAME);
			DataView dvFields = dtFields.DefaultView;

			string sIDSuffix = String.Empty;
			//if ( nRecordIndex > 0 )
			//	sIDSuffix = nRecordIndex.ToString("_##");

			int nColIndex = 0;
			HtmlTableRow  tr      = null;
			HtmlTableCell tdLabel = null;
			HtmlTableCell tdField = null;
			if ( dvFields.Count == 0 && tbl.Rows.Count <= 1 )
				tbl.Visible = false;

			// 01/18/2010   To apply ACL Field Security, we need to know if the current record has an ASSIGNED_USER_ID field, and its value. 
			Guid gASSIGNED_USER_ID = Guid.Empty;
			DataColumnCollection vwSchema = null;
			if ( rdr != null )
			{
				vwSchema = rdr.DataView.Table.Columns;
				if ( vwSchema.Contains("ASSIGNED_USER_ID") )
				{
					gASSIGNED_USER_ID = Sql.ToGuid(rdr["ASSIGNED_USER_ID"]);
				}
			}

			bool bEnableTeamManagement  = Crm.Config.enable_team_management();
			bool bRequireTeamManagement = Crm.Config.require_team_management();
			bool bRequireUserAssignment = Crm.Config.require_user_assignment();
			// 08/01/2010   Allow dynamic teams to be turned off. 
			bool bEnableDynamicTeams   = Crm.Config.enable_dynamic_teams();
			HttpSessionState Session = HttpContext.Current.Session;
			foreach(DataRowView row in dvFields)
			{
				int    nFIELD_INDEX       = Sql.ToInteger(row["FIELD_INDEX"      ]);
				string sFIELD_TYPE        = Sql.ToString (row["FIELD_TYPE"       ]);
				string sDATA_LABEL        = Sql.ToString (row["DATA_LABEL"       ]);
				string sDATA_FIELD        = Sql.ToString (row["DATA_FIELD"       ]);
				string sDISPLAY_FIELD     = Sql.ToString (row["DISPLAY_FIELD"    ]);
				string sCACHE_NAME        = Sql.ToString (row["CACHE_NAME"       ]);
				bool   bDATA_REQUIRED     = Sql.ToBoolean(row["DATA_REQUIRED"    ]);
				bool   bUI_REQUIRED       = Sql.ToBoolean(row["UI_REQUIRED"      ]);
				string sONCLICK_SCRIPT    = Sql.ToString (row["ONCLICK_SCRIPT"   ]);
				string sFORMAT_SCRIPT     = Sql.ToString (row["FORMAT_SCRIPT"    ]);
				short  nFORMAT_TAB_INDEX  = Sql.ToShort  (row["FORMAT_TAB_INDEX" ]);
				int    nFORMAT_MAX_LENGTH = Sql.ToInteger(row["FORMAT_MAX_LENGTH"]);
				int    nFORMAT_SIZE       = Sql.ToInteger(row["FORMAT_SIZE"      ]);
				int    nFORMAT_ROWS       = Sql.ToInteger(row["FORMAT_ROWS"      ]);
				int    nFORMAT_COLUMNS    = Sql.ToInteger(row["FORMAT_COLUMNS"   ]);
				int    nCOLSPAN           = Sql.ToInteger(row["COLSPAN"          ]);
				// 04/02/2008   Add support for Regular Expression validation. 
				string sFIELD_VALIDATOR_MESSAGE = Sql.ToString (row["FIELD_VALIDATOR_MESSAGE"]);
				string sVALIDATION_TYPE         = Sql.ToString (row["VALIDATION_TYPE"        ]);
				string sREGULAR_EXPRESSION      = Sql.ToString (row["REGULAR_EXPRESSION"     ]);
				string sDATA_TYPE               = Sql.ToString (row["DATA_TYPE"              ]);
				string sMININUM_VALUE           = Sql.ToString (row["MININUM_VALUE"          ]);
				string sMAXIMUM_VALUE           = Sql.ToString (row["MAXIMUM_VALUE"          ]);
				string sCOMPARE_OPERATOR        = Sql.ToString (row["COMPARE_OPERATOR"       ]);
				// 09/01/2009   Add support for a generic module popup. 
				string sMODULE_TYPE       = String.Empty;
				try
				{
					sMODULE_TYPE = Sql.ToString (row["MODULE_TYPE"]);
				}
				catch(Exception ex)
				{
					// 09/01/2009   The MODULE_TYPE is not in the view, then log the error and continue. 
					SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
				}
				// 12/24/2008   Each field should be on a new line. 
				nCOLSPAN = 0;
				// 12/27/2008   The data field will need to be in upper case in order for it to be found and saved. 
				sDATA_FIELD    = sDATA_FIELD.ToUpper();
				sDISPLAY_FIELD = sDISPLAY_FIELD.ToUpper();

				// 08/01/2010   To apply ACL Field Security, we need to know if the Module Name, which we will extract from the EditView Name. 
				string sMODULE_NAME = String.Empty;
				string[] arrEDIT_NAME = sEDIT_NAME.Split('.');
				if ( arrEDIT_NAME.Length > 0 )
					sMODULE_NAME = arrEDIT_NAME[0];
				bool bIsReadable  = true;
				bool bIsWriteable = true;
				if ( SplendidInit.bEnableACLFieldSecurity )
				{
					Security.ACL_FIELD_ACCESS acl = Security.GetUserFieldSecurity(sMODULE_NAME, sDATA_FIELD, gASSIGNED_USER_ID);
					bIsReadable  = acl.IsReadable();
					bIsWriteable = acl.IsWriteable();
				}
				// 08/01/2010   If not readable, then just skip the field. 
				if ( !bIsReadable )
					continue;

				sDATA_LABEL = m_sMODULE + ".LBL_" + sDATA_FIELD;
				if ( sDATA_FIELD == "TEAM_ID" || sDATA_FIELD == "TEAM_SET_NAME" )
					sDATA_LABEL = "Teams.LBL_TEAM";
				else if ( sDATA_FIELD == "ASSIGNED_USER_ID" )
					sDATA_LABEL = ".LBL_ASSIGNED_TO";

				// 11/25/2006   If Team Management has been disabled, then convert the field to a blank. 
				// Keep the field, but treat it as blank so that field indexes will still be valid. 
				// 12/03/2006   Allow the team field to be visible during layout. 
				if ( sDATA_FIELD == "TEAM_ID" || sDATA_FIELD == "TEAM_SET_NAME" )
				{
					if ( !bEnableTeamManagement )
					{
						sFIELD_TYPE = "Blank";
						bUI_REQUIRED = false;
					}
					else
					{
						if ( bEnableDynamicTeams )
						{
							// 08/31/2009   Don't convert to TeamSelect inside a Search view or Popup view. 
							if ( sEDIT_NAME.IndexOf(".Search") < 0 && sEDIT_NAME.IndexOf(".Popup") < 0 )
							{
								sDATA_LABEL     = ".LBL_TEAM_SET_NAME";
								sDATA_FIELD     = "TEAM_SET_NAME";
								sFIELD_TYPE     = "TeamSelect";
								sONCLICK_SCRIPT = String.Empty;
							}
						}
						else
						{
							// 04/18/2010   If the user manually adds a TeamSelect, we need to convert to a ModulePopup. 
							if ( sFIELD_TYPE == "TeamSelect" )
							{
								sDATA_LABEL     = "Teams.LBL_TEAM";
								sDATA_FIELD     = "TEAM_ID";
								sDISPLAY_FIELD  = "TEAM_NAME";
								sFIELD_TYPE     = "ModulePopup";
								sMODULE_TYPE    = "Teams";
								sONCLICK_SCRIPT = String.Empty;
							}
						}
						// 11/25/2006   Override the required flag with the system value. 
						// 01/01/2008   If Team Management is not required, then let the admin decide. 
						if ( bRequireTeamManagement )
							bUI_REQUIRED = true;
					}
				}
				// 08/01/2010   Hide the Exchange Folder field if disabled for this module or user. 
				if ( sDATA_FIELD == "EXCHANGE_FOLDER" )
				{
					if ( !Crm.Modules.ExchangeFolders(sMODULE_NAME) || !Security.HasExchangeAlias() )
					{
						sFIELD_TYPE = "Blank";
					}
				}
				if ( String.Compare(sFIELD_TYPE, "AddressButtons", true) == 0 )
					continue;
				else if ( String.Compare(sFIELD_TYPE, "Blank", true) == 0 )
					continue;
				else if ( hashIncludedFields != null && !hashIncludedFields.ContainsKey(sDATA_FIELD) )
					continue;

				if ( sDATA_FIELD == "ASSIGNED_USER_ID" )
				{
					// 01/01/2008   We need a quick way to require user assignments across the system. 
					if ( bRequireUserAssignment )
						bUI_REQUIRED = true;
				}
				// 08/01/2010   Clear the Required flag if the field is writeable. 
				// Clearing at this stage will apply it to all edit types. 
				if ( bUI_REQUIRED && !bIsWriteable )
					bUI_REQUIRED = false;
				if ( (nCOLSPAN >= 0 && nColIndex == 0) || tr == null )
				{
					// 12/27/2008   We need an extra row for the set primary and remove links. 
					if ( nRowIndex == 0 && tbl == tblMain )
					{
						if ( tbl.Rows.Count > nRowIndex )
						{
							tr = tbl.Rows[nRowIndex];
						}
						else
						{
							tr = new HtmlTableRow();
							tbl.Rows.Insert(nRowIndex, tr);
						}
						nRowIndex++;
						tdLabel = new HtmlTableCell();
						tdField = new HtmlTableCell();
						tr.Cells.Add(tdLabel);
						tr.Cells.Add(tdField);
						Label lblPrimaryID = new Label();
						tdField.Controls.Add(lblPrimaryID);
						if ( rdr != null )
						{
							Guid gPrimaryID = Sql.ToGuid(rdr["ID"]);
#if DEBUG
							lblPrimaryID.Text = gPrimaryID.ToString();
#endif
						}
					}
					if ( tbl.Rows.Count > nRowIndex )
					{
						tr = tbl.Rows[nRowIndex];
					}
					else
					{
						tr = new HtmlTableRow();
						tbl.Rows.Insert(nRowIndex, tr);
					}
					nRowIndex++;
				}
				// 12/03/2006   Move literal label up so that it can be accessed when processing a blank. 
				Literal litLabel = new Literal();
				if ( !Sql.IsEmptyString(sDATA_FIELD) )
					litLabel.ID = sDATA_FIELD + "_LABEL" + sIDSuffix;
				if ( nCOLSPAN >= 0 || tdLabel == null || tdField == null )
				{
					tdLabel = new HtmlTableCell();
					tdField = new HtmlTableCell();
					tr.Cells.Add(tdLabel);
					tr.Cells.Add(tdField);
					if ( nCOLSPAN > 0 )
					{
						tdField.ColSpan = nCOLSPAN;
					}
					tdLabel.Attributes.Add("class", "dataLabel");
					tdLabel.VAlign = "top";
					tdLabel.Width  = sFIELD_WIDTH;
					tdField.Attributes.Add("class", "dataField");
					tdField.VAlign = "top";
					tdField.Width  = sFIELD_WIDTH;

					tdLabel.Controls.Add(litLabel);
					//litLabel.Text = nFIELD_INDEX.ToString() + " (" + nRowIndex.ToString() + "," + nColIndex.ToString() + ")";
					try
					{
						// 12/03/2006   Move code to blank able in layout mode to blank section below. 
						if ( sDATA_LABEL.IndexOf(".") >= 0 )
							litLabel.Text = L10n.Term(sDATA_LABEL);
						else if ( !Sql.IsEmptyString(sDATA_LABEL) && rdr != null )
						{
							// 01/27/2008   If the data label is not in the schema table, then it must be free-form text. 
							// It is not used often, but we allow the label to come from the result set.  For example,
							// when the parent is stored in the record, we need to pull the module name from the record. 
							litLabel.Text = sDATA_LABEL;
							if ( rdr.DataView.Table.Columns.Contains(sDATA_LABEL) )
								litLabel.Text = Sql.ToString(rdr[sDATA_LABEL]) + L10n.Term("Calls.LBL_COLON");
						}
						// 07/15/2006   Always put something for the label so that table borders will look right. 
						// 07/20/2007 Vandalo.  Skip the requirement to create a terminology entry and just so the label. 
						else
							litLabel.Text = sDATA_LABEL;  // "&nbsp;";
					}
					catch(Exception ex)
					{
						SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
						litLabel.Text = ex.Message;
					}
					if ( bUI_REQUIRED )
					{
						Label lblRequired = new Label();
						tdLabel.Controls.Add(lblRequired);
						lblRequired.CssClass = "required";
						lblRequired.Text = L10n.Term(".LBL_REQUIRED_SYMBOL");
					}
				}
				
				if ( String.Compare(sFIELD_TYPE, "Label", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						Literal litField = new Literal();
						tdField.Controls.Add(litField);
						// 07/25/2006   Align label values to the middle so the line-up with the label. 
						tdField.VAlign = "middle";
						// 07/24/2006   Set the ID so that the literal control can be accessed. 
						litField.ID = sDATA_FIELD + sIDSuffix;
						try
						{
							if ( sDATA_FIELD.IndexOf(".") >= 0 )
								litField.Text = L10n.Term(sDATA_FIELD);
							else if ( rdr != null )
								litField.Text = Sql.ToString(rdr[sDATA_FIELD]);
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
							litField.Text = ex.Message;
						}
					}
				}
				else if ( String.Compare(sFIELD_TYPE, "ListBox", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						// 12/02/2007   If format rows > 0 then this is a list box and not a drop down list. 
						ListControl lstField = null;
						if ( nFORMAT_ROWS > 0 )
						{
							ListBox lb = new ListBox();
							lb.SelectionMode = ListSelectionMode.Multiple;
							lb.Rows          = nFORMAT_ROWS;
							lstField = lb;
						}
						else
						{
							// 04/25/2008   Use KeySortDropDownList instead of ListSearchExtender. 
							lstField = new KeySortDropDownList();
							// 07/23/2010   Lets try the latest version of the ListSearchExtender. 
							// 07/28/2010   We are getting an undefined exception on the Accounts List Advanced page. 
							// Lets drop back to using KeySort. 
							//lstField = new DropDownList();
						}
						tdField.Controls.Add(lstField);
						lstField.ID       = sDATA_FIELD + sIDSuffix;
						lstField.TabIndex = nFORMAT_TAB_INDEX;
						// 08/01/2010   Apply ACL Field Security. 
						lstField.Enabled  = bIsWriteable;
						// 07/23/2010   Lets try the latest version of the ListSearchExtender. 
						// 07/28/2010   We are getting an undefined exception on the Accounts List Advanced page. 
						/*
						if ( nFORMAT_ROWS == 0 )
						{
							AjaxControlToolkit.ListSearchExtender extField = new AjaxControlToolkit.ListSearchExtender();
							extField.ID              = lstField.ID + "_ListSearchExtender";
							extField.TargetControlID = lstField.ID;
							extField.PromptText      = L10n.Term(".LBL_TYPE_TO_SEARCH");
							extField.PromptCssClass  = "ListSearchExtenderPrompt";
							tdField.Controls.Add(extField);
						}
						*/
						try
						{
							if ( !Sql.IsEmptyString(sDATA_FIELD) )
							{
								// 12/04/2005   Don't populate list if this is a post back. 
								if ( !Sql.IsEmptyString(sCACHE_NAME) && (!bIsPostBack) )
								{
									// 12/24/2007   Use an array to define the custom caches so that list is in the Cache module. 
									// This should reduce the number of times that we have to edit the SplendidDynamic module. 
									// 02/16/2012   Move custom cache logic to a method. 
									SplendidCache.SetListSource(sCACHE_NAME, lstField);
									lstField.DataBind();
									// 08/08/2006   Allow onchange code to be stored in the database.  
									// ListBoxes do not have a useful onclick event, so there should be no problem overloading this field. 
									if ( !Sql.IsEmptyString(sONCLICK_SCRIPT) )
										lstField.Attributes.Add("onchange" , sONCLICK_SCRIPT);
									// 02/21/2006   Move the NONE item inside the !IsPostBack code. 
									// 12/02/2007   We don't need a NONE record when using multi-selection. 
									// 12/03/2007   We do want the NONE record when using multi-selection. 
									// This will allow searching of fields that are null instead of using the unassigned only checkbox. 
									if ( !bUI_REQUIRED )
									{
										lstField.Items.Insert(0, new ListItem(L10n.Term(".LBL_NONE"), ""));
										// 12/02/2007   AppendEditViewFields should be called inside Page_Load when not a postback, 
										// and in InitializeComponent when it is a postback. If done wrong, 
										// the page will bind after the list is populated, causing the list to populate again. 
										// This event will cause the NONE entry to be cleared.  Add a handler to catch this problem, 
										// but the real solution is to call AppendEditViewFields at the appropriate times based on the postback event. 
										lstField.DataBound += new EventHandler(SplendidDynamic.ListControl_DataBound_AllowNull);
									}
								}
								if ( rdr != null )
								{
									try
									{
										// 02/21/2006   All the DropDownLists in the Calls and Meetings edit views were not getting set.  
										// The problem was a Page.DataBind in the SchedulingGrid and in the InviteesView. Both binds needed to be removed. 
										// 12/30/2007   A customer needed the ability to save and restore the multiple selection. 
										// 12/30/2007   Require the XML declaration in the data before trying to treat as XML. 
										string sVALUE = Sql.ToString(rdr[sDATA_FIELD]);
										if ( nFORMAT_ROWS > 0 && sVALUE.StartsWith("<?xml") )
										{
											XmlDocument xml = new XmlDocument();
											xml.LoadXml(sVALUE);
											XmlNodeList nlValues = xml.DocumentElement.SelectNodes("Value");
											foreach ( XmlNode xValue in nlValues )
											{
												foreach ( ListItem item in lstField.Items )
												{
													if ( item.Value == xValue.InnerText )
														item.Selected = true;
												}
											}
										}
										else
										{
											// 08/19/2010   Check the list before assigning the value. 
											Utils.SetSelectedValue(lstField, sVALUE);
										}
									}
									catch(Exception ex)
									{
										SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
									}
								}
							}
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
						}
					}
				}
				// 08/21/2010   Add support for Radio buttons. 
				else if ( String.Compare(sFIELD_TYPE, "Radio", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						ListControl lstField = new RadioButtonList();
						tdField.Controls.Add(lstField);
						lstField.ID       = sDATA_FIELD + sIDSuffix;
						lstField.TabIndex = nFORMAT_TAB_INDEX;
						lstField.CssClass = "radio";
						// 08/01/2010   Apply ACL Field Security. 
						lstField.Enabled  = bIsWriteable;
						try
						{
							if ( !Sql.IsEmptyString(sDATA_FIELD) )
							{
								// 12/04/2005   Don't populate list if this is a post back. 
								if ( !Sql.IsEmptyString(sCACHE_NAME) && (!bIsPostBack) )
								{
									// 12/24/2007   Use an array to define the custom caches so that list is in the Cache module. 
									// This should reduce the number of times that we have to edit the SplendidDynamic module. 
									// 02/16/2012   Move custom cache logic to a method. 
									SplendidCache.SetListSource(sCACHE_NAME, lstField);
									lstField.DataBind();
									if ( !Sql.IsEmptyString(sONCLICK_SCRIPT) )
										lstField.Attributes.Add("onchange" , sONCLICK_SCRIPT);
									if ( !bUI_REQUIRED )
									{
										lstField.Items.Insert(0, new ListItem(L10n.Term(".LBL_NONE"), ""));
										lstField.DataBound += new EventHandler(SplendidDynamic.ListControl_DataBound_AllowNull);
									}
								}
								if ( rdr != null )
								{
									try
									{
										string sVALUE = Sql.ToString(rdr[sDATA_FIELD]);
										if ( sVALUE.StartsWith("<?xml") )
										{
											XmlDocument xml = new XmlDocument();
											xml.LoadXml(sVALUE);
											XmlNodeList nlValues = xml.DocumentElement.SelectNodes("Value");
											foreach ( XmlNode xValue in nlValues )
											{
												foreach ( ListItem item in lstField.Items )
												{
													if ( item.Value == xValue.InnerText )
														item.Selected = true;
												}
											}
										}
										else
										{
											// 08/19/2010   Check the list before assigning the value. 
											Utils.SetSelectedValue(lstField, sVALUE);
										}
									}
									catch(Exception ex)
									{
										SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
									}
								}
							}
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
						}
					}
				}
				// 08/21/2010   Add support for CheckBoxList. 
				else if ( String.Compare(sFIELD_TYPE, "CheckBoxList", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						// 12/02/2007   If format rows > 0 then this is a list box and not a drop down list. 
						ListControl lstField = new CheckBoxList();
						tdField.Controls.Add(lstField);
						lstField.ID       = sDATA_FIELD + sIDSuffix;
						lstField.TabIndex = nFORMAT_TAB_INDEX;
						lstField.CssClass = "checkbox";
						// 08/01/2010   Apply ACL Field Security. 
						lstField.Enabled  = bIsWriteable;
						try
						{
							if ( !Sql.IsEmptyString(sDATA_FIELD) )
							{
								// 12/04/2005   Don't populate list if this is a post back. 
								if ( !Sql.IsEmptyString(sCACHE_NAME) && (!bIsPostBack) )
								{
									// 12/24/2007   Use an array to define the custom caches so that list is in the Cache module. 
									// This should reduce the number of times that we have to edit the SplendidDynamic module. 
									// 02/16/2012   Move custom cache logic to a method. 
									SplendidCache.SetListSource(sCACHE_NAME, lstField);
									lstField.DataBind();
									if ( !Sql.IsEmptyString(sONCLICK_SCRIPT) )
										lstField.Attributes.Add("onchange" , sONCLICK_SCRIPT);
								}
								if ( rdr != null )
								{
									try
									{
										string sVALUE = Sql.ToString(rdr[sDATA_FIELD]);
										if ( sVALUE.StartsWith("<?xml") )
										{
											XmlDocument xml = new XmlDocument();
											xml.LoadXml(sVALUE);
											XmlNodeList nlValues = xml.DocumentElement.SelectNodes("Value");
											foreach ( XmlNode xValue in nlValues )
											{
												foreach ( ListItem item in lstField.Items )
												{
													if ( item.Value == xValue.InnerText )
														item.Selected = true;
												}
											}
										}
										else
										{
											// 08/19/2010   Check the list before assigning the value. 
											Utils.SetSelectedValue(lstField, sVALUE);
										}
									}
									catch(Exception ex)
									{
										SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
									}
								}
							}
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
						}
					}
				}
				else if ( String.Compare(sFIELD_TYPE, "CheckBox", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						CheckBox chkField = new CheckBox();
						tdField.Controls.Add(chkField);
						chkField.ID = sDATA_FIELD + sIDSuffix;
						chkField.CssClass = "checkbox";
						chkField.TabIndex = nFORMAT_TAB_INDEX;
						// 08/01/2010   Apply ACL Field Security. 
						chkField.Enabled  = bIsWriteable;
						try
						{
							if ( rdr != null )
								chkField.Checked = Sql.ToBoolean(rdr[sDATA_FIELD]);
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
						}
						// 07/11/2007   A checkbox can have a click event. 
						if ( !Sql.IsEmptyString(sONCLICK_SCRIPT) )
							chkField.Attributes.Add("onclick", sONCLICK_SCRIPT);
					}
				}
				else if ( String.Compare(sFIELD_TYPE, "ChangeButton", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						//05/06/2010   Manually generate ClearModuleType so that it will be UpdatePanel safe. 
						DropDownList lstField = null;
						// 12/04/2005   If the label is PARENT_TYPE, then change the label to a DropDownList.
						if ( sDATA_LABEL == "PARENT_TYPE" )
						{
							tdLabel.Controls.Clear();
							// 04/25/2008   Use KeySortDropDownList instead of ListSearchExtender. 
							lstField = new KeySortDropDownList();
							// 07/23/2010   Lets try the latest version of the ListSearchExtender. 
							// 07/28/2010   We are getting an undefined exception on the Accounts List Advanced page. 
							// Lets drop back to using KeySort. 
							//lstField = new DropDownList();
							tdLabel.Controls.Add(lstField);
							lstField.ID       = sDATA_LABEL + sIDSuffix;
							lstField.TabIndex = nFORMAT_TAB_INDEX;
							// 07/23/2010   Lets try the latest version of the ListSearchExtender. 
							// 07/28/2010   We are getting an undefined exception on the Accounts List Advanced page. 
							/*
							if ( nFORMAT_ROWS == 0 )
							{
								AjaxControlToolkit.ListSearchExtender extField = new AjaxControlToolkit.ListSearchExtender();
								extField.ID              = lstField.ID + "_ListSearchExtender";
								extField.TargetControlID = lstField.ID;
								extField.PromptText      = L10n.Term(".LBL_TYPE_TO_SEARCH");
								extField.PromptCssClass  = "ListSearchExtenderPrompt";
								tdLabel.Controls.Add(extField);
							}
							*/
							if ( !bIsPostBack )
							{
								// 07/29/2005   SugarCRM 3.0 does not allow the NONE option. 
								lstField.DataValueField = "NAME"        ;
								lstField.DataTextField  = "DISPLAY_NAME";
								lstField.DataSource     = SplendidCache.List("record_type_display");
								lstField.DataBind();
								if ( rdr != null )
								{
									try
									{
										// 08/19/2010   Check the list before assigning the value. 
										Utils.SetSelectedValue(lstField, Sql.ToString(rdr[sDATA_LABEL]));
									}
									catch(Exception ex)
									{
										SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
									}
								}
							}
						}
						TextBox txtNAME = new TextBox();
						tdField.Controls.Add(txtNAME);
						txtNAME.ID       = sDISPLAY_FIELD + sIDSuffix;
						txtNAME.ReadOnly = true;
						txtNAME.TabIndex = nFORMAT_TAB_INDEX;
						// 08/01/2010   Apply ACL Field Security. 
						txtNAME.Enabled  = bIsWriteable;
						// 11/25/2006    Turn off viewstate so that we can fix the text on postback. 
						txtNAME.EnableViewState = false;
						try
						{
							if ( bIsPostBack )
							{
								// 11/25/2006   In order for this posback fix to work, viewstate must be disabled for this field. 
								if ( tbl.Page.Request[txtNAME.UniqueID] != null )
									txtNAME.Text = Sql.ToString(tbl.Page.Request[txtNAME.UniqueID]);
							}
							else if ( !Sql.IsEmptyString(sDISPLAY_FIELD) && rdr != null )
								txtNAME.Text = Sql.ToString(rdr[sDISPLAY_FIELD]);
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
							txtNAME.Text = ex.Message;
						}
						HtmlInputHidden hidID = new HtmlInputHidden();
						tdField.Controls.Add(hidID);
						hidID.ID = sDATA_FIELD + sIDSuffix;
						try
						{
							if ( !Sql.IsEmptyString(sDATA_FIELD) && rdr != null )
								hidID.Value = Sql.ToString(rdr[sDATA_FIELD]);
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
							txtNAME.Text = ex.Message;
						}
						//05/06/2010   Manually generate ClearModuleType so that it will be UpdatePanel safe. 
						// 07/27/2010   Add the ability to submit after clear. 
						if ( sDATA_LABEL == "PARENT_TYPE" && lstField != null )
							lstField.Attributes.Add("onChange", "ClearModuleType('', '" + hidID.ClientID + "', '" + txtNAME.ClientID + "', false);");
						
						Literal litNBSP = new Literal();
						tdField.Controls.Add(litNBSP);
						litNBSP.Text = "&nbsp;";
						
						HtmlInputButton btnChange = new HtmlInputButton("button");
						tdField.Controls.Add(btnChange);
						// 05/07/2006   Specify a name for the check button so that it can be referenced by SplendidTest. 
						btnChange.ID = sDATA_FIELD + "_btnChange" + sIDSuffix;
						btnChange.Attributes.Add("class", "button");
						//05/06/2010   Manually generate ParentPopup so that it will be UpdatePanel safe. 
						if ( lstField != null )
							btnChange.Attributes.Add("onclick", "return ModulePopup(document.getElementById('" + lstField.ClientID + "').options[document.getElementById('" + lstField.ClientID + "').options.selectedIndex].value, '" + hidID.ClientID + "', '" + txtNAME.ClientID + "', null, false, null);");
						else if ( !Sql.IsEmptyString(sONCLICK_SCRIPT) )
							btnChange.Attributes.Add("onclick"  , sONCLICK_SCRIPT);
						// 03/31/2007   SugarCRM now uses Select instead of Change. 
						btnChange.Attributes.Add("title"    , L10n.Term(".LBL_SELECT_BUTTON_TITLE"));
						// 07/31/2006   Stop using VisualBasic library to increase compatibility with Mono. 
						// 03/31/2007   Stop using AccessKey for change button. 
						//btnChange.Attributes.Add("accessKey", L10n.Term(".LBL_SELECT_BUTTON_KEY").Substring(0, 1));
						btnChange.Value = L10n.Term(".LBL_SELECT_BUTTON_LABEL");
						// 08/01/2010   Apply ACL Field Security. 
						btnChange.Disabled = !bIsWriteable;

						// 12/03/2007   Also create a Clear button. 
						// 05/06/2010   A Parent Type will always have a clear button. 
						if ( sONCLICK_SCRIPT.IndexOf("Popup();") > 0 || sDATA_LABEL == "PARENT_TYPE" )
						{
							litNBSP = new Literal();
							tdField.Controls.Add(litNBSP);
							litNBSP.Text = "&nbsp;";
							
							HtmlInputButton btnClear = new HtmlInputButton("button");
							tdField.Controls.Add(btnClear);
							btnClear.ID = sDATA_FIELD + "_btnClear" + sIDSuffix;
							btnClear.Attributes.Add("class", "button");
							//05/06/2010   Manually generate ClearModuleType so that it will be UpdatePanel safe. 
							// 07/27/2010   Add the ability to submit after clear. 
							btnClear.Attributes.Add("onclick"  , "return ClearModuleType('', '" + hidID.ClientID + "', '" + txtNAME.ClientID + "', false);");
							btnClear.Attributes.Add("title"    , L10n.Term(".LBL_CLEAR_BUTTON_TITLE"));
							btnClear.Value = L10n.Term(".LBL_CLEAR_BUTTON_LABEL");
							// 08/01/2010   Apply ACL Field Security. 
							btnClear.Disabled  = !bIsWriteable;
						}
						if ( bUI_REQUIRED && !Sql.IsEmptyString(sDATA_FIELD) )
						{
							RequiredFieldValidatorForHiddenInputs reqID = new RequiredFieldValidatorForHiddenInputs();
							reqID.ID                 = sDATA_FIELD + "_REQUIRED" + sIDSuffix;
							reqID.ControlToValidate  = hidID.ID;
							reqID.ErrorMessage       = L10n.Term(".ERR_REQUIRED_FIELD");
							reqID.CssClass           = "required";
							reqID.EnableViewState    = false;
							// 01/16/2006   We don't enable required fields until we attempt to save. 
							// This is to allow unrelated form actions; the Cancel button is a good example. 
							reqID.EnableClientScript = false;
							reqID.Enabled            = false;
							// 02/21/2008   Add a little padding. 
							reqID.Style.Add("padding-left", "4px");
							tdField.Controls.Add(reqID);
						}
					}
				}
				// 09/01/2009   Add support for ModulePopups.
				// 08/01/2010   Lets do the same for ModuleAutoComplete. 
				else if ( String.Compare(sFIELD_TYPE, "ModulePopup", true) == 0 || String.Compare(sFIELD_TYPE, "ModuleAutoComplete", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						TextBox txtNAME = new TextBox();
						tdField.Controls.Add(txtNAME);
						// 10/05/2010   A custom field will not have a display field, but we still want to be able to access by name. 
						txtNAME.ID       = (Sql.IsEmptyString(sDISPLAY_FIELD) ? sDATA_FIELD + "_NAME" : sDISPLAY_FIELD) + sIDSuffix;
						txtNAME.ReadOnly = true;
						txtNAME.TabIndex = nFORMAT_TAB_INDEX;
						// 11/25/2006    Turn off viewstate so that we can fix the text on postback. 
						txtNAME.EnableViewState = false;
						// 08/01/2010   Apply ACL Field Security. 
						txtNAME.Enabled  = bIsWriteable;
						try
						{
							if ( bIsPostBack )
							{
								// 11/25/2006   In order for this posback fix to work, viewstate must be disabled for this field. 
								if ( tbl.Page.Request[txtNAME.UniqueID] != null )
									txtNAME.Text = Sql.ToString(tbl.Page.Request[txtNAME.UniqueID]);
							}
							else if ( !Sql.IsEmptyString(sDISPLAY_FIELD) && rdr != null )
								txtNAME.Text = Sql.ToString(rdr[sDISPLAY_FIELD]);
							else if ( rdr != null )
								txtNAME.Text = Crm.Modules.ItemName(Application, sMODULE_TYPE, rdr[sDATA_FIELD]);
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
							txtNAME.Text = ex.Message;
						}
						HtmlInputHidden hidID = new HtmlInputHidden();
						tdField.Controls.Add(hidID);
						hidID.ID = sDATA_FIELD + sIDSuffix;
						try
						{
							if ( !Sql.IsEmptyString(sDATA_FIELD) && rdr != null )
								hidID.Value = Sql.ToString(rdr[sDATA_FIELD]);
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
							txtNAME.Text = ex.Message;
						}
						
						Literal litNBSP = new Literal();
						tdField.Controls.Add(litNBSP);
						litNBSP.Text = "&nbsp;";
						
						HtmlInputButton btnChange = new HtmlInputButton("button");
						tdField.Controls.Add(btnChange);
						// 05/07/2006   Specify a name for the check button so that it can be referenced by SplendidTest. 
						btnChange.ID = sDATA_FIELD + "_btnChange" + sIDSuffix;
						btnChange.Attributes.Add("class", "button");
						if ( !Sql.IsEmptyString(sONCLICK_SCRIPT) )
							btnChange.Attributes.Add("onclick"  , sONCLICK_SCRIPT);
						else
							btnChange.Attributes.Add("onclick"  , "return ModulePopup('" + sMODULE_TYPE + "', '" + hidID.ClientID + "', '" + txtNAME.ClientID + "', null, false, null);");
						// 03/31/2007   SugarCRM now uses Select instead of Change. 
						btnChange.Attributes.Add("title"    , L10n.Term(".LBL_SELECT_BUTTON_TITLE"));
						// 07/31/2006   Stop using VisualBasic library to increase compatibility with Mono. 
						// 03/31/2007   Stop using AccessKey for change button. 
						//btnChange.Attributes.Add("accessKey", L10n.Term(".LBL_SELECT_BUTTON_KEY").Substring(0, 1));
						btnChange.Value = L10n.Term(".LBL_SELECT_BUTTON_LABEL");
						// 08/01/2010   Apply ACL Field Security. 
						btnChange.Disabled = !bIsWriteable;

						litNBSP = new Literal();
						tdField.Controls.Add(litNBSP);
						litNBSP.Text = "&nbsp;";
						
						HtmlInputButton btnClear = new HtmlInputButton("button");
						tdField.Controls.Add(btnClear);
						btnClear.ID = sDATA_FIELD + "_btnClear" + sIDSuffix;
						btnClear.Attributes.Add("class", "button");
						// 07/27/2010   Add the ability to submit after clear. 
						btnClear.Attributes.Add("onclick"  , "return ClearModuleType('" + sMODULE_TYPE + "', '" + hidID.ClientID + "', '" + txtNAME.ClientID + "', false);");
						btnClear.Attributes.Add("title"    , L10n.Term(".LBL_CLEAR_BUTTON_TITLE"));
						btnClear.Value = L10n.Term(".LBL_CLEAR_BUTTON_LABEL");
						// 08/01/2010   Apply ACL Field Security. 
						btnClear.Disabled = !bIsWriteable;

						if ( bUI_REQUIRED && !Sql.IsEmptyString(sDATA_FIELD) )
						{
							RequiredFieldValidatorForHiddenInputs reqID = new RequiredFieldValidatorForHiddenInputs();
							reqID.ID                 = sDATA_FIELD + "_REQUIRED" + sIDSuffix;
							reqID.ControlToValidate  = hidID.ID;
							reqID.ErrorMessage       = L10n.Term(".ERR_REQUIRED_FIELD");
							reqID.CssClass           = "required";
							reqID.EnableViewState    = false;
							// 01/16/2006   We don't enable required fields until we attempt to save. 
							// This is to allow unrelated form actions; the Cancel button is a good example. 
							reqID.EnableClientScript = false;
							reqID.Enabled            = false;
							// 02/21/2008   Add a little padding. 
							reqID.Style.Add("padding-left", "4px");
							tdField.Controls.Add(reqID);
						}
					}
				}
				else if ( String.Compare(sFIELD_TYPE, "TextBox", true) == 0 || String.Compare(sFIELD_TYPE, "Password", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						TextBox txtField = new TextBox();
						tdField.Controls.Add(txtField);
						txtField.ID       = sDATA_FIELD + sIDSuffix;
						txtField.TabIndex = nFORMAT_TAB_INDEX;
						// 08/01/2010   Apply ACL Field Security. 
						txtField.Enabled  = bIsWriteable;
						try
						{
							if ( nFORMAT_ROWS > 0 && nFORMAT_COLUMNS > 0 )
							{
								txtField.Rows     = nFORMAT_ROWS   ;
								txtField.Columns  = nFORMAT_COLUMNS;
								txtField.TextMode = TextBoxMode.MultiLine;
							}
							else
							{
								txtField.MaxLength = nFORMAT_MAX_LENGTH   ;
								txtField.Attributes.Add("size", nFORMAT_SIZE.ToString());
								txtField.TextMode  = TextBoxMode.SingleLine;
							}
							if ( !Sql.IsEmptyString(sDATA_FIELD) && rdr != null )
							{
								if ( rdr[sDATA_FIELD].GetType() == typeof(System.Decimal) )
									txtField.Text = Sql.ToDecimal(rdr[sDATA_FIELD]).ToString("#,##0.00");
								else
									txtField.Text = Sql.ToString(rdr[sDATA_FIELD]);
							}
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
							txtField.Text = ex.Message;
						}
						if ( String.Compare(sFIELD_TYPE, "Password", true) == 0 )
							txtField.TextMode = TextBoxMode.Password;
						if ( bUI_REQUIRED && !Sql.IsEmptyString(sDATA_FIELD) )
						{
							RequiredFieldValidator reqNAME = new RequiredFieldValidator();
							reqNAME.ID                 = sDATA_FIELD + "_REQUIRED" + sIDSuffix;
							reqNAME.ControlToValidate  = txtField.ID;
							reqNAME.ErrorMessage       = L10n.Term(".ERR_REQUIRED_FIELD");
							reqNAME.CssClass           = "required";
							reqNAME.EnableViewState    = false;
							// 01/16/2006   We don't enable required fields until we attempt to save. 
							// This is to allow unrelated form actions; the Cancel button is a good example. 
							reqNAME.EnableClientScript = false;
							reqNAME.Enabled            = false;
							reqNAME.Style.Add("padding-left", "4px");
							tdField.Controls.Add(reqNAME);
						}
						if ( !Sql.IsEmptyString(sDATA_FIELD) )
						{
							if ( sVALIDATION_TYPE == "RegularExpressionValidator" && !Sql.IsEmptyString(sREGULAR_EXPRESSION) && !Sql.IsEmptyString(sFIELD_VALIDATOR_MESSAGE) && bIsWriteable )
							{
								RegularExpressionValidator reqVALIDATOR = new RegularExpressionValidator();
								reqVALIDATOR.ID                   = sDATA_FIELD + "_VALIDATOR" + sIDSuffix;
								reqVALIDATOR.ControlToValidate    = txtField.ID;
								reqVALIDATOR.ErrorMessage         = L10n.Term(sFIELD_VALIDATOR_MESSAGE);
								reqVALIDATOR.ValidationExpression = sREGULAR_EXPRESSION;
								reqVALIDATOR.CssClass             = "required";
								reqVALIDATOR.EnableViewState      = false;
								// 04/02/2008   We don't enable required fields until we attempt to save. 
								// This is to allow unrelated form actions; the Cancel button is a good example. 
								reqVALIDATOR.EnableClientScript   = false;
								reqVALIDATOR.Enabled              = false;
								reqVALIDATOR.Style.Add("padding-left", "4px");
								tdField.Controls.Add(reqVALIDATOR);
							}
						}
					}
				}
				// 04/04/2011   Add support for HtmlEditor. 
				else if ( String.Compare(sFIELD_TYPE, "HtmlEditor", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						// 09/18/2011   Upgrade to CKEditor 3.6.2. 
						CKEditorControl txtField = new CKEditorControl();
						tdField.Controls.Add(txtField);
						txtField.ID         = sDATA_FIELD;
						txtField.Toolbar    = "Taoqi";
						// 09/18/2011   Set the language for CKEditor. 
						txtField.Language   = L10n.NAME;
						txtField.BasePath   = "~/ckeditor/";
						// 04/26/2012   Add file uploader. 
						txtField.FilebrowserUploadUrl    = txtField.ResolveUrl("~/ckeditor/upload.aspx");
						txtField.FilebrowserBrowseUrl    = txtField.ResolveUrl("~/Images/Popup.aspx");
						//txtField.FilebrowserWindowWidth  = "640";
						//txtField.FilebrowserWindowHeight = "480";
						txtField.Visible  = bIsWriteable;
						try
						{
							if ( nFORMAT_ROWS > 0 && nFORMAT_COLUMNS > 0 )
							{
								txtField.Height = nFORMAT_ROWS   ;
								// 04/04/2011   Reduce the width to make it easier to edit. 
								txtField.Width  = nFORMAT_COLUMNS / 2;
							}
							if ( !Sql.IsEmptyString(sDATA_FIELD) && rdr != null )
							{
								txtField.Text = Sql.ToString(rdr[sDATA_FIELD]);
								// 01/18/2010   FCKEditor does not have an Enable field, so just hide and replace with a Literal control. 
								if ( !bIsWriteable )
								{
									txtField.Visible = false;
									Literal litField = new Literal();
									litField.ID = sDATA_FIELD + "_ReadOnly";
									tdField.Controls.Add(litField);
									litField.Text = Sql.ToString(rdr[sDATA_FIELD]);
								}
							}
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
							txtField.Text = ex.Message;
						}
					}
				}
				else if ( String.Compare(sFIELD_TYPE, "DatePicker", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						// 12/03/2005   UserControls must be loaded. 
						DatePicker ctlDate = tbl.Page.LoadControl("~/_controls/DatePicker.ascx") as DatePicker;
						tdField.Controls.Add(ctlDate);
						ctlDate.ID = sDATA_FIELD + sIDSuffix;
						// 05/10/2006   Set the tab index. 
						ctlDate.TabIndex = nFORMAT_TAB_INDEX;
						// 08/01/2010   Apply ACL Field Security. 
						ctlDate.Enabled  = bIsWriteable;
						try
						{
							if ( rdr != null )
								ctlDate.Value = T10n.FromServerTime(rdr[sDATA_FIELD]);
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
						}
					}
				}
				else if ( String.Compare(sFIELD_TYPE, "DateRange", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						// 12/17/2007   Use table to align before and after labels. 
						Table tblDateRange = new Table();
						tdField.Controls.Add(tblDateRange);
						TableRow trAfter = new TableRow();
						TableRow trBefore = new TableRow();
						tblDateRange.Rows.Add(trAfter);
						tblDateRange.Rows.Add(trBefore);
						TableCell tdAfterLabel  = new TableCell();
						TableCell tdAfterData   = new TableCell();
						TableCell tdBeforeLabel = new TableCell();
						TableCell tdBeforeData  = new TableCell();
						trAfter .Cells.Add(tdAfterLabel );
						trAfter .Cells.Add(tdAfterData  );
						trBefore.Cells.Add(tdBeforeLabel);
						trBefore.Cells.Add(tdBeforeData );

						// 12/03/2005   UserControls must be loaded. 
						DatePicker ctlDateStart = tbl.Page.LoadControl("~/_controls/DatePicker.ascx") as DatePicker;
						DatePicker ctlDateEnd   = tbl.Page.LoadControl("~/_controls/DatePicker.ascx") as DatePicker;
						Literal litAfterLabel  = new Literal();
						Literal litBeforeLabel = new Literal();
						litAfterLabel .Text = L10n.Term("SavedSearch.LBL_SEARCH_AFTER" );
						litBeforeLabel.Text = L10n.Term("SavedSearch.LBL_SEARCH_BEFORE");
						//tdField.Controls.Add(litAfterLabel );
						//tdField.Controls.Add(ctlDateStart  );
						//tdField.Controls.Add(litBeforeLabel);
						//tdField.Controls.Add(ctlDateEnd    );
						tdAfterLabel .Controls.Add(litAfterLabel );
						tdAfterData  .Controls.Add(ctlDateStart  );
						tdBeforeLabel.Controls.Add(litBeforeLabel);
						tdBeforeData .Controls.Add(ctlDateEnd    );

						ctlDateStart.ID = sDATA_FIELD + "_AFTER" + sIDSuffix;
						ctlDateEnd  .ID = sDATA_FIELD + "_BEFORE" + sIDSuffix;
						// 05/10/2006   Set the tab index. 
						ctlDateStart.TabIndex = nFORMAT_TAB_INDEX;
						ctlDateEnd  .TabIndex = nFORMAT_TAB_INDEX;
						// 08/01/2010   Apply ACL Field Security. 
						ctlDateStart.Enabled  = bIsWriteable;
						ctlDateEnd  .Enabled  = bIsWriteable;
						try
						{
							if ( rdr != null )
							{
								ctlDateStart.Value = T10n.FromServerTime(rdr[sDATA_FIELD]);
								ctlDateEnd  .Value = T10n.FromServerTime(rdr[sDATA_FIELD]);
							}
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
						}
					}
				}
				else if ( String.Compare(sFIELD_TYPE, "DateTimePicker", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						// 12/03/2005   UserControls must be loaded. 
						DateTimePicker ctlDate = tbl.Page.LoadControl("~/_controls/DateTimePicker.ascx") as DateTimePicker;
						tdField.Controls.Add(ctlDate);
						ctlDate.ID = sDATA_FIELD + sIDSuffix;
						// 05/10/2006   Set the tab index. 
						ctlDate.TabIndex = nFORMAT_TAB_INDEX;
						// 08/01/2010   Apply ACL Field Security. 
						ctlDate.Enabled  = bIsWriteable;
						try
						{
							if ( rdr != null )
								ctlDate.Value = T10n.FromServerTime(rdr[sDATA_FIELD]);
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
						}
					}
				}
				else if ( String.Compare(sFIELD_TYPE, "DateTimeEdit", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						// 12/03/2005   UserControls must be loaded. 
						DateTimeEdit ctlDate = tbl.Page.LoadControl("~/_controls/DateTimeEdit.ascx") as DateTimeEdit;
						tdField.Controls.Add(ctlDate);
						ctlDate.ID = sDATA_FIELD + sIDSuffix;
						// 05/10/2006   Set the tab index. 
						ctlDate.TabIndex = nFORMAT_TAB_INDEX;
						// 08/01/2010   Apply ACL Field Security. 
						ctlDate.Enabled  = bIsWriteable;
						try
						{
							if ( rdr != null )
								ctlDate.Value = T10n.FromServerTime(rdr[sDATA_FIELD]);
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
						}
						if ( bUI_REQUIRED )
						{
							ctlDate.EnableNone = false;
						}
					}
				}
				else if ( String.Compare(sFIELD_TYPE, "File", true) == 0 )
				{
					// 11/23/2010   File should act just like an image. 
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						HtmlInputHidden ctlHidden = null;
						HtmlInputFile   ctlField  = new HtmlInputFile();
						tdField.Controls.Add(ctlField);
						// 04/17/2006   The image needs to reference the file control. 
						// 11/25/2010   Appending _File breaks the previous behavior of Notes, Bugs and Documents.
						// 11/25/2010   The file field is special in that it may not exist as a table column. 
						ctlField.ID = sDATA_FIELD + sIDSuffix;
						if ( rdr != null )
						{
							if ( vwSchema.Contains(sDATA_FIELD) )
							{
								ctlField.ID = sDATA_FIELD + "_File" + sIDSuffix;
								ctlHidden = new HtmlInputHidden();
								tdField.Controls.Add(ctlHidden);
								ctlHidden.ID = sDATA_FIELD + sIDSuffix;
							}
						}
						ctlField.MaxLength = nFORMAT_MAX_LENGTH;
						ctlField.Size      = nFORMAT_SIZE;
						ctlField.Attributes.Add("TabIndex", nFORMAT_TAB_INDEX.ToString());
						// 08/01/2010   Apply ACL Field Security. 
						ctlField.Disabled  = !bIsWriteable;
						if ( bUI_REQUIRED )
						{
							RequiredFieldValidator reqNAME = new RequiredFieldValidator();
							reqNAME.ID                 = sDATA_FIELD + "_REQUIRED" + sIDSuffix;
							reqNAME.ControlToValidate  = ctlField.ID;
							reqNAME.ErrorMessage       = L10n.Term(".ERR_REQUIRED_FIELD");
							reqNAME.CssClass           = "required";
							reqNAME.EnableViewState    = false;
							// 01/16/2006   We don't enable required fields until we attempt to save. 
							// This is to allow unrelated form actions; the Cancel button is a good example. 
							reqNAME.EnableClientScript = false;
							reqNAME.Enabled            = false;
							reqNAME.Style.Add("padding-left", "4px");
							tdField.Controls.Add(reqNAME);
						}

						Literal litBR = new Literal();
						litBR.Text = "<br />";
						tdField.Controls.Add(litBR);
						
						HyperLink lnkField = new HyperLink();
						// 04/13/2006   Give the image a name so that it can be validated with SplendidTest. 
						lnkField.ID = "lnk" + sDATA_FIELD + sIDSuffix;
						try
						{
							if ( rdr != null )
							{
								// 11/25/2010   The file field is special in that it may not exist as a table column. 
								if ( ctlHidden != null && !Sql.IsEmptyString(rdr[sDATA_FIELD]) )
								{
									ctlHidden.Value = Sql.ToString(rdr[sDATA_FIELD]);
									lnkField.NavigateUrl = "~/Images/Image.aspx?ID=" + ctlHidden.Value;
									lnkField.Text = Crm.Modules.ItemName(Application, "Images", ctlHidden.Value);
									// 04/13/2006   Only add the image if it exists. 
									tdField.Controls.Add(lnkField);
									
									// 04/17/2006   Provide a clear button. 
									Literal litClear = new Literal();
									litClear.Text = "&nbsp; <input type=\"button\" class=\"button\" onclick=\"document.getElementById('" + ctlHidden.ClientID + "').value='';document.getElementById('" + lnkField.ClientID + "').innerHTML='';" + "\"  value='" + "  " + L10n.Term(".LBL_CLEAR_BUTTON_LABEL" ) + "  " + "' title='" + L10n.Term(".LBL_CLEAR_BUTTON_TITLE" ) + "' />";
									tdField.Controls.Add(litClear);
								}
							}
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
							Literal litField = new Literal();
							litField.Text = ex.Message;
							tdField.Controls.Add(litField);
						}
					}
				}
				else if ( String.Compare(sFIELD_TYPE, "Image", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						HtmlInputHidden ctlHidden = new HtmlInputHidden();
						tdField.Controls.Add(ctlHidden);
						ctlHidden.ID = sDATA_FIELD + sIDSuffix;

						HtmlInputFile ctlField = new HtmlInputFile();
						tdField.Controls.Add(ctlField);
						// 04/17/2006   The image needs to reference the file control. 
						ctlField.ID = sDATA_FIELD + "_File" + sIDSuffix;
						ctlField.MaxLength = nFORMAT_MAX_LENGTH;
						ctlField.Size      = nFORMAT_SIZE;
						ctlField.Attributes.Add("TabIndex", nFORMAT_TAB_INDEX.ToString());
						// 08/01/2010   Apply ACL Field Security. 
						ctlField.Disabled  = !bIsWriteable;
						if ( bUI_REQUIRED )
						{
							RequiredFieldValidator reqNAME = new RequiredFieldValidator();
							reqNAME.ID                 = sDATA_FIELD + "_REQUIRED" + sIDSuffix;
							reqNAME.ControlToValidate  = ctlField.ID;
							reqNAME.ErrorMessage       = L10n.Term(".ERR_REQUIRED_FIELD");
							reqNAME.CssClass           = "required";
							reqNAME.EnableViewState    = false;
							// 01/16/2006   We don't enable required fields until we attempt to save. 
							// This is to allow unrelated form actions; the Cancel button is a good example. 
							reqNAME.EnableClientScript = false;
							reqNAME.Enabled            = false;
							reqNAME.Style.Add("padding-left", "4px");
							tdField.Controls.Add(reqNAME);
						}

						Literal litBR = new Literal();
						litBR.Text = "<br />";
						tdField.Controls.Add(litBR);
						
						Image imgField = new Image();
						// 04/13/2006   Give the image a name so that it can be validated with SplendidTest. 
						imgField.ID = "img" + sDATA_FIELD + sIDSuffix;
						try
						{
							if ( rdr != null )
							{
								if ( !Sql.IsEmptyString(rdr[sDATA_FIELD]) )
								{
									ctlHidden.Value = Sql.ToString(rdr[sDATA_FIELD]);
									imgField.ImageUrl = "~/Images/Image.aspx?ID=" + ctlHidden.Value;
									// 04/13/2006   Only add the image if it exists. 
									tdField.Controls.Add(imgField);
									
									// 04/17/2006   Provide a clear button. 
									Literal litClear = new Literal();
									litClear.Text = "&nbsp; <input type=\"button\" class=\"button\" onclick=\"document.getElementById('" + ctlHidden.ClientID + "').value='';document.getElementById('" + imgField.ClientID + "').src='';" + "\"  value='" + "  " + L10n.Term(".LBL_CLEAR_BUTTON_LABEL" ) + "  " + "' title='" + L10n.Term(".LBL_CLEAR_BUTTON_TITLE" ) + "' />";
									tdField.Controls.Add(litClear);
								}
							}
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
							Literal litField = new Literal();
							litField.Text = ex.Message;
							tdField.Controls.Add(litField);
						}
					}
				}
				// 04/04/2011   Add support for hidden field. 
				else if ( String.Compare(sFIELD_TYPE, "Hidden", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						HtmlInputHidden hidID = new HtmlInputHidden();
						tdField.Controls.Add(hidID);
						hidID.ID = sDATA_FIELD + sIDSuffix;
						try
						{
							if ( !Sql.IsEmptyString(sDATA_FIELD) && rdr != null )
								hidID.Value = Sql.ToString(rdr[sDATA_FIELD]);
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
						}
					}
				}
				// 08/01/2010   Add support for dynamic teams. 
				else if ( String.Compare(sFIELD_TYPE, "TeamSelect", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						TeamSelect ctlTeamSelect = tbl.Page.LoadControl("~/_controls/TeamSelect.ascx") as TeamSelect;
						tdField.Controls.Add(ctlTeamSelect);
						ctlTeamSelect.ID = sDATA_FIELD;
						// 05/06/2010   Use a special Page flag to override the default IsPostBack behavior. 
						ctlTeamSelect.NotPostBack = !bIsPostBack;
						//ctlTeamSelect.TabIndex = nFORMAT_TAB_INDEX;
						// 08/01/2010   Apply ACL Field Security. 
						ctlTeamSelect.Enabled  = bIsWriteable;
						try
						{
							Guid gTEAM_SET_ID = Guid.Empty;
							if ( rdr != null )
							{
								if ( vwSchema.Contains("TEAM_SET_ID") )
								{
									gTEAM_SET_ID = Sql.ToGuid(rdr["TEAM_SET_ID"]);
								}
							}
							// 08/31/2009  Don't provide defaults in a Search view or a Popup view. 
							bool bAllowDefaults = sEDIT_NAME.IndexOf(".Search") < 0 && sEDIT_NAME.IndexOf(".Popup") < 0;
							ctlTeamSelect.LoadLineItems(gTEAM_SET_ID, bAllowDefaults);
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
						}
					}
				}
				// 04/04/2011   Add support for dynamic teams. 
				else if ( String.Compare(sFIELD_TYPE, "KBTagSelect", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						KBTagSelect ctlKBTagSelect = tbl.Page.LoadControl("~/_controls/KBTagSelect.ascx") as KBTagSelect;
						tdField.Controls.Add(ctlKBTagSelect);
						ctlKBTagSelect.ID = sDATA_FIELD;
						// 05/06/2010   Use a special Page flag to override the default IsPostBack behavior. 
						ctlKBTagSelect.NotPostBack = !bIsPostBack;
						//ctlTeamSelect.TabIndex = nFORMAT_TAB_INDEX;
						// 08/01/2010   Apply ACL Field Security. 
						ctlKBTagSelect.Enabled  = bIsWriteable;
						try
						{
							Guid gID = Guid.Empty;
							if ( rdr != null )
							{
								gID = Sql.ToGuid(rdr["ID"]);
							}
							ctlKBTagSelect.LoadLineItems(gID);
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
						}
					}
				}
				else
				{
					Literal litField = new Literal();
					tdField.Controls.Add(litField);
					litField.Text = "Unknown field type " + sFIELD_TYPE;
					SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), "Unknown field type " + sFIELD_TYPE);
				}
				nColIndex = 0;
			}
		}
示例#39
0
		/// <summary>
		/// 填充 CheckBoxList 控件
		/// </summary>
		/// <param name="_CuDDL">CheckBoxList控件ID</param>
		/// <param name="_SqlStr">支持的SQL语句</param>
		/// <param name="_Table_Name">视图标识</param>
		/// <param name="_Value">数据字段</param>
		/// <param name="_Mc">显示字段</param>
		/// <param name="_ErrorsWZ">记录程序中的位置</param>
		public static void Fill_ChecBoxList(CheckBoxList _CuDDL,string _SqlStr,string _Table_Name,string _Value,string _Mc,string _ErrorsWZ)
		{
			SqlConnection _Conn = new SqlConnection(ConfigurationSettings.AppSettings["YJH"]);
			try
			{
				_CuDDL.DataSource =dataview_2 (_Conn,_SqlStr,_Table_Name);
				_CuDDL.DataTextField =_Mc;
				_CuDDL.DataValueField = _Value;
				_CuDDL.DataBind ();
			}
			catch(Exception _ex)
			{
				throw new Exception(_ex.Message.ToString());
			}			
			finally
			{
				if(_Conn!=null) _Conn.Dispose ();
			}			
		}
示例#40
0
 public void FillToCheckBoxList(CheckBoxList checkboxlist, DataTable datatable, string displayMember, string valueMember)
 {
     if (datatable != null)
     {
         checkboxlist.DataSource = datatable;
         checkboxlist.DataTextField = displayMember;
         checkboxlist.DataValueField = valueMember;
     }
     else
     {
         checkboxlist.DataSource = null;
     }
     checkboxlist.DataBind();
 }
 protected void BindList()
 {
     chkIpList.DataSource = GetDataTable(Config.DbGetAllowedIP);
     chkIpList.DataBind();
 }
示例#42
0
        private void GenrateForm()
        {
            try
            {
                if (pnlForm.Controls.Count == 1)
                {
                    var LINQProfile = db.sp_ProfileListActive(GetPortalID);
                    CommonFunction LToDCon = new CommonFunction();
                    DataTable dt = LToDCon.LINQToDataTable(LINQProfile);
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        Table tblSageForm = new Table();
                        tblSageForm.CssClass = "cssClassForm";
                        tblSageForm.ID = "tblSageForm";
                        tblSageForm.EnableViewState = true;
                        string parentKey = string.Empty;
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            int ProfileID = Int32.Parse(dt.Rows[i]["ProfileID"].ToString());
                            TableRow tbrSageRow = new TableRow();
                            tbrSageRow.ID = "tbrSageRow_" + ProfileID;
                            tbrSageRow.EnableViewState = true;

                            TableCell tcleftSagetd = new TableCell();
                            tcleftSagetd.ID = "tcleftSagetd_" + ProfileID;
                            tcleftSagetd.CssClass = "cssClassFormtdLleft";
                            tcleftSagetd.EnableViewState = true;
                            tcleftSagetd.Width = Unit.Percentage(20);

                            Label lblValue = new Label();
                            lblValue.ID = "lblValue_" + ProfileID;
                            lblValue.Text = dt.Rows[i]["Name"].ToString();
                            lblValue.ToolTip = dt.Rows[i]["Name"].ToString();
                            lblValue.EnableViewState = true;
                            lblValue.CssClass = "cssClassFormLabel";

                            tcleftSagetd.Controls.Add(lblValue);

                            tbrSageRow.Cells.Add(tcleftSagetd);

                            
                            int PropertyTypeID = Int32.Parse(dt.Rows[i]["PropertyTypeID"].ToString());

                            TableCell tcrightSagetd = new TableCell();
                            tcrightSagetd.ID = "tcrightSagetd_" + ProfileID;
                            tcrightSagetd.CssClass = "cssClassFormtdRight";
                            tcrightSagetd.EnableViewState = true;

                            
                            

                            switch (PropertyTypeID)
                            {
                                case 1://TextBox
                                    TextBox BDTextBox = new TextBox();
                                    BDTextBox.ID = "BDTextBox_" + ProfileID;
                                    BDTextBox.CssClass = "cssClassNormalTextBox";
                                    BDTextBox.EnableViewState = true;



                                    int DataType = Int32.Parse(dt.Rows[i]["DataType"].ToString());
                                    switch (DataType)
                                    {
                                        case 0://String
                                            //Adding in Pandel
                                            tcrightSagetd.Controls.Add(BDTextBox);
                                            break;
                                        case 1://Integer
                                            BDTextBox.Attributes.Add("OnKeydown", "return NumberKey(event)");
                                            //Adding in Pandel
                                            tcrightSagetd.Controls.Add(BDTextBox);
                                            break;
                                        case 2://Decimal
                                            BDTextBox.Attributes.Add("OnKeydown", "return NumberKeyWithDecimal(event)");
                                            //Adding in Pandel
                                            tcrightSagetd.Controls.Add(BDTextBox);
                                            break;
                                        case 3://DateTime
                                            ImageButton imb = new ImageButton();
                                            imb.ID = "imb_" + ProfileID;
                                            imb.ImageUrl = GetTemplateImageUrl("imgcalendar.png", true);

                                            CalendarExtender Cex = new CalendarExtender();
                                            Cex.ID = "Cex_" + ProfileID;
                                            Cex.TargetControlID = BDTextBox.ID;
                                            Cex.PopupButtonID = imb.ID;
                                            Cex.SelectedDate = DateTime.Now;
                                            BDTextBox.ToolTip = "DateTime";
                                            BDTextBox.Enabled = false;

                                            //Adding in Panel
                                            tcrightSagetd.Controls.Add(BDTextBox);
                                            tcrightSagetd.Controls.Add(imb);
                                            tcrightSagetd.Controls.Add(Cex);
                                            break;

                                    }

                                    

                                    bool IsRequred = bool.Parse(dt.Rows[i]["IsRequired"].ToString());
                                    if (IsRequred)
                                    {
                                        RequiredFieldValidator rfv = new RequiredFieldValidator();
                                        rfv.ID = "rfv_" + ProfileID;
                                        rfv.ControlToValidate = BDTextBox.ID;
                                        rfv.ErrorMessage = "*";
                                        rfv.ValidationGroup = "UserProfile";
                                        tcrightSagetd.Controls.Add(rfv);
                                    }
                                    

                                    break;
                                case 2://DropDownList
                                    DropDownList ddl = new DropDownList();
                                    ddl.ID = "BDTextBox_" + ProfileID;
                                    ddl.CssClass = "cssClassDropDown";
                                    //ddl.Width = 200;
                                    ddl.EnableViewState = true;

                                    //Setting Data Source
                                    var LinqProvileValue = db.sp_ProfileValueGetActiveByProfileID(ProfileID, GetPortalID);
                                    ddl.DataSource = LinqProvileValue;
                                    ddl.DataValueField = "ProfileValueID";
                                    ddl.DataTextField = "Name";
                                    ddl.DataBind();
                                    if (ddl.Items.Count > 0)
                                    {
                                        ddl.SelectedIndex = 0;
                                    }

                                    //Adding in Pandel
                                    tcrightSagetd.Controls.Add(ddl);
                                    break;
                                case 3://CheckBoxList
                                    CheckBoxList chbl = new CheckBoxList();
                                    chbl.ID = "BDTextBox_" + ProfileID;
                                    chbl.CssClass = "cssClassCheckBox";
                                    chbl.RepeatDirection = System.Web.UI.WebControls.RepeatDirection.Horizontal;
                                    chbl.RepeatColumns = 2;
                                    chbl.EnableViewState = true;

                                    //Setting Data Source
                                    LinqProvileValue = db.sp_ProfileValueGetActiveByProfileID(ProfileID, GetPortalID);
                                    chbl.DataSource = LinqProvileValue;
                                    chbl.DataValueField = "ProfileValueID";
                                    chbl.DataTextField = "Name";
                                    chbl.DataBind();
                                    if (chbl.Items.Count > 0)
                                    {
                                        chbl.SelectedIndex = 0;
                                    }

                                    //Adding in Pandel
                                    tcrightSagetd.Controls.Add(chbl);
                                    break;
                                case 4://RadioButtonList
                                    RadioButtonList rdbl = new RadioButtonList();
                                    rdbl.ID = "BDTextBox_" + ProfileID;
                                    rdbl.CssClass = "cssClassRadioButtonList";
                                    rdbl.EnableViewState = true;
                                    rdbl.RepeatDirection = System.Web.UI.WebControls.RepeatDirection.Horizontal;
                                    rdbl.RepeatColumns = 2;

                                    //Setting Data Source
                                    LinqProvileValue = db.sp_ProfileValueGetActiveByProfileID(ProfileID, GetPortalID);
                                    rdbl.DataSource = LinqProvileValue;
                                    rdbl.DataValueField = "ProfileValueID";
                                    rdbl.DataTextField = "Name";
                                    rdbl.DataBind();
                                    if (rdbl.Items.Count > 0)
                                    {
                                        rdbl.SelectedIndex = 0;
                                    }
									tcrightSagetd.CssClass = "cssClassButtonListWrapper";
                                    //Adding in Pandel
                                    tcrightSagetd.Controls.Add(rdbl);
                                    break;
                                case 5://DropDownList
                                    DropDownList cddl = new DropDownList();
                                    cddl.ID = "BDTextBox_" + ProfileID;
                                    cddl.CssClass = "cssClassDropDown";
                                    //cddl.Width = 200;
                                    cddl.EnableViewState = true;
                                    cddl.SelectedIndexChanged +=new EventHandler(cddl_SelectedIndexChanged);
                                    cddl.AutoPostBack = true;
                                    ViewState["cddlID"] = cddl.ID;
                                    //Setting Data Source
                                    ListManagementDataContext cdb = new ListManagementDataContext(SystemSetting.SageFrameConnectionString);
                                    var CLINQ = cdb.sp_GetListEntrybyNameAndID("Country", -1,GetCurrentCultureName);                                   
                                    cddl.DataSource = CLINQ;
                                    cddl.DataValueField = "Value";
                                    cddl.DataTextField = "Text";
                                    cddl.DataBind();
                                    if (cddl.Items.Count > 0)
                                    {
                                        cddl.SelectedIndex = 0;
                                        parentKey = "Country." + cddl.SelectedItem.Value;
                                    }

                                    //Adding in Pandel
                                    tcrightSagetd.Controls.Add(cddl);
                                    break;
                                case 6://DropDownList
                                    DropDownList Sddl = new DropDownList();
                                    Sddl.ID = "BDTextBox_" + ProfileID;
                                    Sddl.CssClass = "cssClassNormalTextBox";
                                    //Sddl.Width = 200;
                                    Sddl.EnableViewState = true;
                                    ViewState["SddlID"] = Sddl.ID;
                                    //Setting Data Source
                                    string listName = "Region";
                                    ListManagementDataContext Sdb = new ListManagementDataContext(SystemSetting.SageFrameConnectionString);
                                    var listDetail = Sdb.sp_GetListEntriesByNameParentKeyAndPortalID(listName, parentKey, -1,GetCurrentCultureName);
                                    Sddl.DataSource = listDetail;
                                    Sddl.DataValueField = "Value";
                                    Sddl.DataTextField = "Text";
                                    Sddl.DataBind();
                                    if (Sddl.Items.Count > 0)
                                    {
                                        Sddl.SelectedIndex = 0;
                                    }
                                    ViewState["StateRow"] = tbrSageRow.ID;

                                    //Adding in Pandel
                                    tcrightSagetd.Controls.Add(Sddl);
                                    break;
                                case 7://DropDownList
                                    DropDownList TimeZoneddl = new DropDownList();
                                    TimeZoneddl.ID = "BDTextBox_" + ProfileID;
                                    TimeZoneddl.CssClass = "cssClassDropDown";
                                    //TimeZoneddl.Width = 200;
                                    TimeZoneddl.EnableViewState = true;

                                    //Setting Data Source
                                    NameValueCollection nvlTimeZone = SageFrame.Localization.Localization.GetTimeZones(((PageBase)this.Page).GetCurrentCultureName);
                                    TimeZoneddl.DataSource = nvlTimeZone;                                    
                                    TimeZoneddl.DataBind();
                                    if (TimeZoneddl.Items.Count > 0)
                                    {
                                        TimeZoneddl.SelectedIndex = 0;                                       
                                    }

                                    //Adding in Pandel
                                    tcrightSagetd.Controls.Add(TimeZoneddl);
                                    break;
                                case 8://File Upload
                                    FileUpload AsyFlu = new FileUpload();
                                    AsyFlu.ID = "BDTextBox_" + ProfileID;
                                    AsyFlu.CssClass = "cssClassNormalFileUpload";                                    
                                    AsyFlu.EnableViewState = true;
                                    tcrightSagetd.Controls.Add(AsyFlu);

                                    System.Web.UI.HtmlControls.HtmlGenericControl gcDiv = new HtmlGenericControl("div");
                                    gcDiv.ID = "BDDiv_" + ProfileID;
                                    gcDiv.Attributes.Add("class","cssClassProfileImageWrapper");
                                    gcDiv.EnableViewState = true;
                                    gcDiv.Visible = false;

                                    Image img = new Image();
                                    img.ID = "Bdimg_" + ProfileID;
                                    img.CssClass = "cssClassProfileImage";
                                    img.EnableViewState = true;
                                    gcDiv.Controls.Add(img);
                                    tcrightSagetd.Controls.Add(gcDiv);
                                    break;
                            }
                            tbrSageRow.Cells.Add(tcrightSagetd);
                            tblSageForm.Rows.Add(tbrSageRow);
                            pnlForm.Controls.Add(tblSageForm);
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                ProcessException(ex);
            }
        }
示例#43
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="cbl"></param>
        public static void BindLowLevelWaterUser(WaterUserClass parent, CheckBoxList cbl)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }
            if (cbl == null)
            {
                throw new ArgumentNullException("ddl");
            }

            NameIDPairCollection nips = new NameIDPairCollection();
            foreach (WaterUserClass w in parent.LowLevelWaterUserCollection)
            {
                NameIDPair ni = new NameIDPair(w.Name, w.WaterUserID);
                nips.Add(ni);
            }

            cbl.DataSource = nips;
            cbl.DataTextField = "Name";
            cbl.DataValueField = "id";
            cbl.DataBind();
        }
示例#44
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="cbl"></param>
        public static void DataBind(WaterUserClass parentWaterUser, CheckBoxList cbl)
        {
            if (parentWaterUser == null)
            {
                return;
            }

            object ds = parentWaterUser.LowLevelWaterUserCollection;
            cbl.DataSource = ds;
            cbl.DataTextField = "Name";
            cbl.DataValueField = "WaterUserID";
            cbl.DataBind();
        }
示例#45
0
        public static bool LoadCheckBoxList(CheckBoxList _CheckBoxList, object objData, string dataTextField,
            string dataValueField)
        {
            if (objData != null)
            {
                _CheckBoxList.DataSource = null;
                _CheckBoxList.Items.Clear();

                _CheckBoxList.DataSource = objData;
                _CheckBoxList.DataTextField = dataTextField;
                _CheckBoxList.DataValueField = dataValueField;

                try
                {
                    _CheckBoxList.DataBind();
                }
                catch
                {
                    return false;
                }
                return true;
            }
            return false;
        }
示例#46
0
        protected void BindCheckBoxList(DataTable table, CheckBoxList checkBoxList, List<string> selectedIDs)
        {
            checkBoxList.DataSource = table;
            checkBoxList.DataBind();

            // check selected ids
            foreach (ListItem item in checkBoxList.Items)
            {
                foreach (string selectedID in selectedIDs)
                    if (item.Value == selectedID)
                        item.Selected = true;
            }
        }
示例#47
0
        private void PopulateSurvey(SurveyResponse response, UtilityBL.Mode mode)
        {
            var survey = response.SurveyTitle;

            if (survey == null)
            {
                lblSurveyTitle.Text = "Invalid Survey";
                return;
            }
            lblSurveyTitle.Text = survey.SurveyTitle1;
            lblSurveyDescription.Text = survey.Description;

            var score = 0;
            var hasAnswers = false;
            if (response.QuestionResponses.Any())
                hasAnswers = true;

            foreach (var section in survey.SurveySections)
            {

                var divSection = new HtmlGenericControl("div");
                divSection.Attributes.Add("id", "divSection" + section.SurveySectionId.ToString());
                divSection.Attributes.Add("class", "panel panel-info");

                if (section.SectionTypeId == (int)UtilityBL.SectionType.Doctor)
                {
                    if (mode != UtilityBL.Mode.Entry)
                        pnlDoctorSection.Controls.Add(divSection);
                    else
                        continue;
                }
                else
                    Panel1.Controls.Add(divSection);

                var divSectionTitle = new HtmlGenericControl("div");
                divSectionTitle.Attributes.Add("id", "divSectionTitle" + section.SurveySectionId.ToString());
                divSectionTitle.Attributes.Add("class", "panel-heading");
                divSection.Controls.Add(divSectionTitle);

                if (section.DisplaySectionHeader && !string.IsNullOrEmpty(section.SurveySectionTtile))
                {
                    var lblSectionTitle = new Label();
                    lblSectionTitle.Text = section.SurveySectionTtile;
                    lblSectionTitle.Font.Bold = true;
                    lblSectionTitle.Font.Size = FontUnit.Large;
                    divSectionTitle.Controls.Add(lblSectionTitle);

                    if (!string.IsNullOrEmpty(section.SurveySectionDesc))
                    {
                        var sectionPara = new HtmlGenericControl("p");
                        sectionPara.Attributes.Add("id", "p" + section.SurveySectionId.ToString());
                        divSectionTitle.Controls.Add(sectionPara);

                        var lblSectionDescription = new Label();
                        lblSectionDescription.Text = section.SurveySectionDesc;
                        lblSectionDescription.Font.Size = FontUnit.Small;
                        sectionPara.Controls.Add(lblSectionDescription);
                    }
                }

                var divSectionBody = new HtmlGenericControl("div");
                divSectionBody.Attributes.Add("id", "divSectionBody" + section.SurveySectionId.ToString());
                divSectionBody.Attributes.Add("class", "panel-body");
                divSection.Controls.Add(divSectionBody);

                foreach (var q in section.Questions)
                {
                    var divQuestion = new HtmlGenericControl("div");
                    divQuestion.Attributes.Add("id", "divQuestion" + q.QuestionId.ToString());
                    divQuestion.Attributes.Add("class", "panel panel-default");
                    divSectionBody.Controls.Add(divQuestion);

                    var divQuestionTitle = new HtmlGenericControl("div");
                    divQuestionTitle.Attributes.Add("id", "divQuestionTitle" + q.QuestionId.ToString());
                    divQuestionTitle.Attributes.Add("class", "panel-heading");
                    divQuestion.Controls.Add(divQuestionTitle);


                    var lblQuestion = new Label();
                    lblQuestion.Text = q.Question1;
                    lblQuestion.ID = "lblQuestion" + q.QuestionId.ToString();
                    lblQuestion.Font.Bold = true;
                    divQuestionTitle.Controls.Add(lblQuestion);

                    var divQuestionBody = new HtmlGenericControl("div");
                    divQuestionBody.Attributes.Add("class", "panel-body");
                    divQuestionBody.Attributes.Add("id", "divQuestionBody" + q.QuestionId.ToString());
                    divQuestion.Controls.Add(divQuestionBody);

                    if (q.QuestionTypeId == 1)
                    {
                        var rdbList = new RadioButtonList();
                        rdbList.ID = "ctrl" + q.QuestionId.ToString();
                        rdbList.DataTextField = "QuestionOption1";
                        rdbList.DataValueField = "QuestionOptionId";
                        rdbList.DataSource = q.QuestionOptions;
                        rdbList.DataBind();
                        rdbList.Attributes.Add("class", "radio radiobuttonlist");

                        if (hasAnswers)
                        {
                            var answr = q.QuestionResponses.FirstOrDefault(r => r.SurveyResponse.SurveyResponseId == response.SurveyResponseId);
                            if (answr != null)
                                rdbList.SelectedValue = answr.QuestionOptionId.ToString();
                        }

                        if (q.DependentonQuestion != null)
                        {
                            var parentAnswer = q.DependentonQuestion.QuestionResponses.FirstOrDefault(r => r.SurveyResponse.SurveyResponseId == response.SurveyResponseId);
                            if (parentAnswer == null || q.EnabledValue != parentAnswer.ResponseText)
                            {
                                foreach (ListItem radio in rdbList.Items)
                                    radio.Enabled = false;
                            }
                        }
                            
                        divQuestionBody.Controls.Add(rdbList);
                    }

                    else if (q.QuestionTypeId == 2)
                    {
                        var chkList = new CheckBoxList();
                        chkList.ID = "ctrl" + q.QuestionId.ToString();
                        chkList.DataTextField = "QuestionOption1";
                        chkList.DataValueField = "QuestionOptionId";
                        chkList.DataSource = q.QuestionOptions;
                        chkList.DataBind();
                        chkList.Attributes.Add("class", "checkbox checked-list-box");

                        if (hasAnswers)
                        {
                            foreach (ListItem item in chkList.Items)
                            {
                                if (q.QuestionResponses.Any(r => r.QuestionOptionId == Convert.ToInt32(item.Value) && r.SurveyResponse.SurveyResponseId == response.SurveyResponseId))
                                {
                                    item.Selected = true;
                                    var qOption = q.QuestionOptions.FirstOrDefault(o => o.QuestionOptionId == Convert.ToInt32(item.Value));
                                }
                            }
                        }

                        if (q.DependentonQuestion != null)
                            chkList.Attributes.Add("disabled", "disabled");

                        divQuestionBody.Controls.Add(chkList);
                    }

                    if (q.QuestionTypeId == 3)
                    {
                        var txt = new TextBox();
                        txt.ID = "ctrl" + q.QuestionId.ToString();
                        txt.Attributes.Add("class", "form-control input-md col-md-10");
                        txt.Attributes.Add("style", "width:80%; max-width:700px;");

                        if (hasAnswers)
                        {
                            var answr = q.QuestionResponses.FirstOrDefault(r => r.SurveyResponse.SurveyResponseId == response.SurveyResponseId);
                            if (answr != null)
                                txt.Text = answr.ResponseText;
                        }

                        if (mode == UtilityBL.Mode.ViewMode || mode == UtilityBL.Mode.ApproveMode)
                            txt.ReadOnly = true;

                        if (q.DependentonQuestion != null)
                            txt.Attributes.Add("disabled", "disabled");

                        divQuestionBody.Controls.Add(txt);
                    }
                }
            }
            if ((mode == UtilityBL.Mode.ViewMode || mode == UtilityBL.Mode.ApproveMode)
                && survey.SurveySections.Any(s => s.Questions.Any(q => q.QuestionOptions.Sum(o => o.Value ?? 0) > 0)))
            {
                score = response.QuestionResponses.Where(x => x.Question.SurveySection.SectionTypeId == (int)UtilityBL.SectionType.Patient)
                                            .Select(s => s.QuestionOption.Value).Sum(r => r.Value);

                var interpretation = _db.InterpretationDetails.FirstOrDefault(d => d.SurveyInterpretation.SurveyTitleId == response.SurveyTitleId
                                                                && d.ScoreRangeStart >= score && score <= d.ScoreRangeEnd);

                if (interpretation != null)
                {
                    pnlSurveyInterpretation.Visible = true;

                    lblScore.Text = score.ToString();
                    lblResult.Text = interpretation.Result;

                    if (!string.IsNullOrEmpty(interpretation.Action))
                        lblAction.Text = interpretation.Action;
                    else
                        lblACtionCaption.Visible = false;
                }
            }

            if (mode == UtilityBL.Mode.ApproveMode)
                DependetQuestionState(response, UtilityBL.SectionType.Doctor);
            else if (mode == UtilityBL.Mode.Entry)
                DependetQuestionState(response, UtilityBL.SectionType.Patient);
        }       
        /// <summary>
        /// Populates the roles.
        /// </summary>
        /// <param name="listRoles">The list roles.</param>
        /// <param name="moduleRoles">The module roles.</param>
        private void PopulateRoles(ref CheckBoxList listRoles, string moduleRoles)
        {
            // Get roles from db
            var users = new UsersDB();
            var roles = users.GetPortalRoles(this.PortalSettings.PortalAlias);

            // Clear existing items in checkbox list
            listRoles.Items.Clear();

            // All Users
            var allItem = new ListItem("All Users");
            listRoles.Items.Add(allItem);

            // Authenticated user role added 15 nov 2002 - by manudea
            var authItem = new ListItem("Authenticated Users");
            listRoles.Items.Add(authItem);

            // Unauthenticated user role added 30/01/2003 - by manudea
            var unauthItem = new ListItem("Unauthenticated Users");
            listRoles.Items.Add(unauthItem);

            listRoles.DataSource = roles;
            listRoles.DataTextField = "Name";
            listRoles.DataValueField = "Id";
            listRoles.DataBind();

            // Splits up the role string and use array 30/01/2003 - by manudea
            while (moduleRoles.EndsWith(";"))
            {
                moduleRoles = moduleRoles.Substring(0, moduleRoles.Length - 1);
            }

            var arrModuleRoles = moduleRoles.Split(';');
            var roleCount = arrModuleRoles.GetUpperBound(0);

            // Cycle every role and select it if needed
            foreach (ListItem ls in listRoles.Items)
            {
                for (var i = 0; i <= roleCount; i++)
                {
                    if (arrModuleRoles[i].ToLower() == ls.Text.ToLower())
                    {
                        ls.Selected = true;
                    }
                }
            }
        }
示例#49
0
        public void gPopulateCheckBoxList(CheckBoxList chklist, string strSQLQuery,string strTextField,string strValueField)
        {
            try
            {

                if (strSQLQuery != null || strSQLQuery != "")
                {

                    chklist.Items.Clear();

                    chklist.DataSource = objHelper.gReturnDataSet(CommandType.Text, strSQLQuery);

                    chklist.DataTextField = strTextField;
                    chklist.DataValueField = strValueField;

                    chklist.DataBind();
                }

            }
            catch
            {
                throw new Exception();
            }
        }
示例#50
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="channelID"></param>
        /// <param name="cblStation"></param>
        /// <param name="isSelected"></param>
        public static void StationOfChannelBind(int channelID, CheckBoxList cblStation, bool isSelected)
        {
            //ListItem item = this.ddlChannel.SelectedItem;
            //if (item != null)
            //{
            //int id = int.Parse(item.Value);
            //WaterUserClass wu = GetWaterUser();
            //if (wu != null)
            //{
            //ChannelClass ch = wu.ChannelCollection.GetChannelByID(id);
            ChannelClass ch = ChannelFactory.CreateChannel(channelID);
            if (ch != null)
            {
                ListItemCollection stationList = GetStationListItemCollection(ch.StationCollection);
                cblStation.DataTextField = "Text";
                cblStation.DataValueField = "Value";
                cblStation.DataSource = stationList;
                cblStation.DataBind();

                foreach (ListItem stitem in cblStation.Items)
                {
                    stitem.Selected = isSelected;
                }
            }
            //}
            //}
        }
示例#51
0
		public static void AppendEditViewFields(DataView dvFields, HtmlTable tbl, DataRow rdr, L10N L10n, TimeZone T10n, CommandEventHandler Page_Command, bool bLayoutMode, string sSubmitClientID)
		{
			bool bIsMobile = false;
			SplendidPage Page = tbl.Page as SplendidPage;
			if ( Page != null )
				bIsMobile = Page.IsMobile;
			// 06/21/2009   We need the script manager to properly register EnterKey presses for text boxes. 
			ScriptManager mgrAjax = ScriptManager.GetCurrent(tbl.Page);
			// 11/23/2009   Taoqi 4.0 is very slow on Blackberry devices.  Lets try and turn off AJAX AutoComplete. 
			bool bAjaxAutoComplete = (mgrAjax != null);
			// 12/07/2009   The Opera Mini browser does not support popups. Use a DropdownList instead. 
			bool bSupportsPopups = true;
			if ( bIsMobile )
			{
				// 11/24/2010   .NET 4 has broken the compatibility of the browser file system. 
				// We are going to minimize our reliance on browser files in order to reduce deployment issues. 
				bAjaxAutoComplete = Utils.AllowAutoComplete && (mgrAjax != null);
				bSupportsPopups = Utils.SupportsPopups;
			}
			// 07/28/2010   Save AjaxAutoComplete and SupportsPopups for use in TeamSelect and KBSelect. 
			// We are having issues with the data binding event occurring before the page load. 
			Page.Items["AjaxAutoComplete"] = bAjaxAutoComplete;
			Page.Items["SupportsPopups"  ] = bSupportsPopups  ;
			// 05/06/2010   Use a special Page flag to override the default IsPostBack behavior. 
			bool bIsPostBack = tbl.Page.IsPostBack;
			bool bNotPostBack = false;
			if ( tbl.TemplateControl is SplendidControl )
			{
				bNotPostBack = (tbl.TemplateControl as SplendidControl).NotPostBack;
				bIsPostBack = tbl.Page.IsPostBack && !bNotPostBack;
			}

			HtmlTableRow tr = null;
			// 11/28/2005   Start row index using the existing count so that headers can be specified. 
			int nRowIndex = tbl.Rows.Count - 1;
			int nColIndex = 0;
			HtmlTableCell tdLabel = null;
			HtmlTableCell tdField = null;
			// 01/07/2006   Show table borders in layout mode. This will help distinguish blank lines from wrapped lines. 
			if ( bLayoutMode )
				tbl.Border = 1;
			// 11/15/2007   If there are no fields in the detail view, then hide the entire table. 
			// This allows us to hide the table by removing all detail view fields. 
			// 09/12/2009   There is no reason to hide the table when in layout mode. 
			if ( dvFields.Count == 0 && tbl.Rows.Count <= 1 && !bLayoutMode )
				tbl.Visible = false;

			// 01/27/2008   We need the schema table to determine if the data label is free-form text. 
			// 03/21/2008   We need to use a view to search for the rows for the ColumnName. 
			// 01/18/2010   To apply ACL Field Security, we need to know if the current record has an ASSIGNED_USER_ID field, and its value. 
			Guid gASSIGNED_USER_ID = Guid.Empty;
			//DataView vwSchema = null;
			if ( rdr != null )
			{
				// 11/22/2010   Convert data reader to data table for Rules Wizard. 
				//vwSchema = new DataView(rdr.GetSchemaTable());
				//vwSchema.RowFilter = "ColumnName = 'ASSIGNED_USER_ID'";
				//if ( vwSchema.Count > 0 )
				if ( rdr.Table.Columns.Contains("ASSIGNED_USER_ID") )
				{
					gASSIGNED_USER_ID = Sql.ToGuid(rdr["ASSIGNED_USER_ID"]);
				}
			}

			// 01/01/2008   Pull config flag outside the loop. 
			bool bEnableTeamManagement  = Crm.Config.enable_team_management();
			bool bRequireTeamManagement = Crm.Config.require_team_management();
			// 01/01/2008   We need a quick way to require user assignments across the system. 
			bool bRequireUserAssignment = Crm.Config.require_user_assignment();
			// 08/28/2009   Allow dynamic teams to be turned off. 
			bool bEnableDynamicTeams   = Crm.Config.enable_dynamic_teams();
			HttpSessionState Session = HttpContext.Current.Session;
			HttpApplicationState Application = HttpContext.Current.Application;
			// 10/07/2010   Convert the currency values before displaying. 
			// The UI culture should already be set to format the currency. 
			Currency C10n = HttpContext.Current.Items["C10n"] as Currency;
			// 05/08/2010   Define the copy buttons outside the loop so that we can replace the javascript with embedded code. 
			// This is so that the javascript will run properly in the SixToolbar UpdatePanel. 
			HtmlInputButton btnCopyRight = null;
			HtmlInputButton btnCopyLeft  = null;
			// 09/13/2010   We need to prevent duplicate names. 
			Hashtable hashLABEL_IDs = new Hashtable();
			bool bSupportsDraggable = Sql.ToBoolean(Session["SupportsDraggable"]);
			// 12/13/2013   Allow each line item to have a separate tax rate. 
			bool bEnableTaxLineItems = Sql.ToBoolean(HttpContext.Current.Application["CONFIG.Orders.TaxLineItems"]);
			foreach(DataRowView row in dvFields)
			{
				string sEDIT_NAME         = Sql.ToString (row["EDIT_NAME"        ]);
				int    nFIELD_INDEX       = Sql.ToInteger(row["FIELD_INDEX"      ]);
				string sFIELD_TYPE        = Sql.ToString (row["FIELD_TYPE"       ]);
				string sDATA_LABEL        = Sql.ToString (row["DATA_LABEL"       ]);
				string sDATA_FIELD        = Sql.ToString (row["DATA_FIELD"       ]);
				// 01/19/2010   We need to be able to format a Float field to prevent too many decimal places. 
				string sDATA_FORMAT       = Sql.ToString (row["DATA_FORMAT"      ]);
				string sDISPLAY_FIELD     = Sql.ToString (row["DISPLAY_FIELD"    ]);
				string sCACHE_NAME        = Sql.ToString (row["CACHE_NAME"       ]);
				bool   bDATA_REQUIRED     = Sql.ToBoolean(row["DATA_REQUIRED"    ]);
				bool   bUI_REQUIRED       = Sql.ToBoolean(row["UI_REQUIRED"      ]);
				string sONCLICK_SCRIPT    = Sql.ToString (row["ONCLICK_SCRIPT"   ]);
				string sFORMAT_SCRIPT     = Sql.ToString (row["FORMAT_SCRIPT"    ]);
				short  nFORMAT_TAB_INDEX  = Sql.ToShort  (row["FORMAT_TAB_INDEX" ]);
				int    nFORMAT_MAX_LENGTH = Sql.ToInteger(row["FORMAT_MAX_LENGTH"]);
				int    nFORMAT_SIZE       = Sql.ToInteger(row["FORMAT_SIZE"      ]);
				// 11/02/2010   We need a way to insert NONE into the a ListBox while still allowing multiple rows. 
				// The trick will be to use a negative number.  Use an absolute value here to reduce the areas to fix. 
				int    nFORMAT_ROWS       = Math.Abs(Sql.ToInteger(row["FORMAT_ROWS"]));
				int    nFORMAT_COLUMNS    = Sql.ToInteger(row["FORMAT_COLUMNS"   ]);
				int    nCOLSPAN           = Sql.ToInteger(row["COLSPAN"          ]);
				int    nROWSPAN           = Sql.ToInteger(row["ROWSPAN"          ]);
				string sLABEL_WIDTH       = Sql.ToString (row["LABEL_WIDTH"      ]);
				string sFIELD_WIDTH       = Sql.ToString (row["FIELD_WIDTH"      ]);
				int    nDATA_COLUMNS      = Sql.ToInteger(row["DATA_COLUMNS"     ]);
				// 05/17/2009   Add support for a generic module popup. 
				string sMODULE_TYPE       = String.Empty;
				try
				{
					sMODULE_TYPE = Sql.ToString (row["MODULE_TYPE"]);
				}
				catch(Exception ex)
				{
					// 05/17/2009   The MODULE_TYPE is not in the view, then log the error and continue. 
					SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
				}
				// 09/13/2010   Add relationship fields. 
				bool   bVALID_RELATED                = false;
				string sRELATED_SOURCE_MODULE_NAME   = String.Empty;
				string sRELATED_SOURCE_VIEW_NAME     = String.Empty;
				string sRELATED_SOURCE_ID_FIELD      = String.Empty;
				string sRELATED_SOURCE_NAME_FIELD    = String.Empty;
				string sRELATED_VIEW_NAME            = String.Empty;
				string sRELATED_ID_FIELD             = String.Empty;
				string sRELATED_NAME_FIELD           = String.Empty;
				string sRELATED_JOIN_FIELD           = String.Empty;
				try
				{
					sRELATED_SOURCE_MODULE_NAME   = Sql.ToString (row["RELATED_SOURCE_MODULE_NAME"  ]);
					sRELATED_SOURCE_VIEW_NAME     = Sql.ToString (row["RELATED_SOURCE_VIEW_NAME"    ]);
					sRELATED_SOURCE_ID_FIELD      = Sql.ToString (row["RELATED_SOURCE_ID_FIELD"     ]);
					sRELATED_SOURCE_NAME_FIELD    = Sql.ToString (row["RELATED_SOURCE_NAME_FIELD"   ]);
					sRELATED_VIEW_NAME            = Sql.ToString (row["RELATED_VIEW_NAME"           ]);
					sRELATED_ID_FIELD             = Sql.ToString (row["RELATED_ID_FIELD"            ]);
					sRELATED_NAME_FIELD           = Sql.ToString (row["RELATED_NAME_FIELD"          ]);
					sRELATED_JOIN_FIELD           = Sql.ToString (row["RELATED_JOIN_FIELD"          ]);
					bVALID_RELATED =  !Sql.IsEmptyString(sRELATED_SOURCE_VIEW_NAME) && !Sql.IsEmptyString(sRELATED_SOURCE_ID_FIELD) && !Sql.IsEmptyString(sRELATED_SOURCE_NAME_FIELD) 
					               && !Sql.IsEmptyString(sRELATED_VIEW_NAME       ) && !Sql.IsEmptyString(sRELATED_ID_FIELD       ) && !Sql.IsEmptyString(sRELATED_NAME_FIELD       ) 
					               && !Sql.IsEmptyString(sRELATED_JOIN_FIELD      );
				}
				catch(Exception ex)
				{
					SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
				}
				// 10/09/2010   Add PARENT_FIELD so that we can establish dependent listboxes. 
				string sPARENT_FIELD = String.Empty;
				try
				{
					sPARENT_FIELD = Sql.ToString (row["PARENT_FIELD"]);
				}
				catch(Exception ex)
				{
					// 05/17/2009   The PARENT_FIELD is not in the view, then log the error and continue. 
					SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
				}

				// 04/02/2008   Add support for Regular Expression validation. 
				string sFIELD_VALIDATOR_MESSAGE = Sql.ToString (row["FIELD_VALIDATOR_MESSAGE"]);
				string sVALIDATION_TYPE         = Sql.ToString (row["VALIDATION_TYPE"        ]);
				string sREGULAR_EXPRESSION      = Sql.ToString (row["REGULAR_EXPRESSION"     ]);
				string sDATA_TYPE               = Sql.ToString (row["DATA_TYPE"              ]);
				string sMININUM_VALUE           = Sql.ToString (row["MININUM_VALUE"          ]);
				string sMAXIMUM_VALUE           = Sql.ToString (row["MAXIMUM_VALUE"          ]);
				string sCOMPARE_OPERATOR        = Sql.ToString (row["COMPARE_OPERATOR"       ]);
				// 06/12/2009   Add TOOL_TIP for help hover.
				string sTOOL_TIP                = String.Empty;
				try
				{
					sTOOL_TIP = Sql.ToString (row["TOOL_TIP"]);
				}
				catch(Exception ex)
				{
					// 06/12/2009   The TOOL_TIP is not in the view, then log the error and continue. 
					SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
				}
				
				// 12/02/2007   Each view can now have its own number of data columns. 
				// This was needed so that search forms can have 4 data columns. The default is 2 columns. 
				if ( nDATA_COLUMNS == 0 )
					nDATA_COLUMNS = 2;

				// 01/18/2010   To apply ACL Field Security, we need to know if the Module Name, which we will extract from the EditView Name. 
				string sMODULE_NAME = String.Empty;
				string[] arrEDIT_NAME = sEDIT_NAME.Split('.');
				if ( arrEDIT_NAME.Length > 0 )
					sMODULE_NAME = arrEDIT_NAME[0];
				bool bIsReadable  = true;
				bool bIsWriteable = true;
				if ( SplendidInit.bEnableACLFieldSecurity )
				{
					Security.ACL_FIELD_ACCESS acl = Security.GetUserFieldSecurity(sMODULE_NAME, sDATA_FIELD, gASSIGNED_USER_ID);
					bIsReadable  = acl.IsReadable();
					// 02/16/2011   We should allow a Read-Only field to be searchable, so always allow writing if the name contains Search. 
					bIsWriteable = acl.IsWriteable() || sEDIT_NAME.Contains(".Search");
				}

				// 11/25/2006   If Team Management has been disabled, then convert the field to a blank. 
				// Keep the field, but treat it as blank so that field indexes will still be valid. 
				// 12/03/2006   Allow the team field to be visible during layout. 
				if ( !bLayoutMode && (sDATA_FIELD == "TEAM_ID" || sDATA_FIELD == "TEAM_SET_NAME") )
				{
					if ( !bEnableTeamManagement )
					{
						sFIELD_TYPE = "Blank";
						bUI_REQUIRED = false;
					}
					else
					{
						// 08/28/2012   DATA_FORMAT for TEAM_ID is 1 when we want to force ModulePopup. 
						if ( bEnableDynamicTeams && sDATA_FORMAT != "1" )
						{
							// 08/31/2009   Don't convert to TeamSelect inside a Search view or Popup view. 
							if ( sEDIT_NAME.IndexOf(".Search") < 0 && sEDIT_NAME.IndexOf(".Popup") < 0 )
							{
								sDATA_LABEL     = ".LBL_TEAM_SET_NAME";
								sDATA_FIELD     = "TEAM_SET_NAME";
								sFIELD_TYPE     = "TeamSelect";
								sONCLICK_SCRIPT = String.Empty;
							}
						}
						else
						{
							// 04/18/2010   If the user manually adds a TeamSelect, we need to convert to a ModulePopup. 
							if ( sFIELD_TYPE == "TeamSelect" )
							{
								sDATA_LABEL     = "Teams.LBL_TEAM";
								sDATA_FIELD     = "TEAM_ID";
								sDISPLAY_FIELD  = "TEAM_NAME";
								sFIELD_TYPE     = "ModulePopup";
								sMODULE_TYPE    = "Teams";
								sONCLICK_SCRIPT = String.Empty;
							}
						}
						// 11/25/2006   Override the required flag with the system value. 
						// 01/01/2008   If Team Management is not required, then let the admin decide. 
						if ( bRequireTeamManagement )
							bUI_REQUIRED = true;
					}
				}
				// 12/13/2013   Allow each product to have a default tax rate. 
				if ( !bLayoutMode && sDATA_FIELD == "TAX_CLASS" )
				{
					if ( bEnableTaxLineItems )
					{
						// 08/28/2009   If dynamic teams are enabled, then always use the set name. 
						sDATA_LABEL = "ProductTemplates.LBL_TAXRATE_ID";
						sDATA_FIELD = "TAXRATE_ID";
						sCACHE_NAME = "TaxRates";
					}
				}
				// 04/04/2010   Hide the Exchange Folder field if disabled for this module or user. 
				if ( !bLayoutMode && sDATA_FIELD == "EXCHANGE_FOLDER" )
				{
					if ( !Crm.Modules.ExchangeFolders(sMODULE_NAME) || !Security.HasExchangeAlias() )
					{
						sFIELD_TYPE = "Blank";
					}
				}
				if ( !bLayoutMode && sDATA_FIELD == "ASSIGNED_USER_ID" )
				{
					// 01/01/2008   We need a quick way to require user assignments across the system. 
					if ( bRequireUserAssignment )
						bUI_REQUIRED = true;
				}
				if ( bIsMobile && String.Compare(sFIELD_TYPE, "AddressButtons", true) == 0 )
				{
					// 11/17/2007   Skip the address buttons on a mobile device. 
					continue;
				}
				// 01/18/2010   Clear the Required flag if the field is not writeable. 
				// Clearing at this stage will apply it to all edit types. 
				if ( bUI_REQUIRED && !bIsWriteable )
					bUI_REQUIRED = false;
				// 09/02/2012   A separator will create a new table. We need to match the outer and inner layout. 
				if ( String.Compare(sFIELD_TYPE, "Separator", true) == 0 )
				{
					if ( tbl.Parent.Parent.Parent is System.Web.UI.WebControls.Table )
					{
						System.Web.UI.WebControls.Table tblOuter = new System.Web.UI.WebControls.Table();
						tblOuter.SkinID = "tabForm";
						tblOuter.Style.Add(HtmlTextWriterStyle.MarginTop, "5px");
						// 09/27/2012   Separator can have an ID and can have a style so that it can be hidden. 
						if ( !Sql.IsEmptyString(sDATA_FIELD) )
							tblOuter.ID = sDATA_FIELD;
						if ( !Sql.IsEmptyString(sDATA_FORMAT) && !bLayoutMode )
							tblOuter.Style.Add(HtmlTextWriterStyle.Display, sDATA_FORMAT);
						int nParentIndex = tbl.Parent.Parent.Parent.Parent.Controls.IndexOf(tbl.Parent.Parent.Parent);
						tbl.Parent.Parent.Parent.Parent.Controls.AddAt(nParentIndex + 1, tblOuter);
						System.Web.UI.WebControls.TableRow trOuter = new System.Web.UI.WebControls.TableRow();
						tblOuter.Rows.Add(trOuter);
						System.Web.UI.WebControls.TableCell tdOuter = new System.Web.UI.WebControls.TableCell();
						trOuter.Cells.Add(tdOuter);
						System.Web.UI.HtmlControls.HtmlTable tblInner = new System.Web.UI.HtmlControls.HtmlTable();
						tblInner.Attributes.Add("class", "tabEditView");
						tdOuter.Controls.Add(tblInner);
						tbl = tblInner;
					
						nRowIndex = -1;
						nColIndex = 0;
						tdLabel = null;
						tdField = null;
						if ( bLayoutMode )
							tbl.Border = 1;
						else
							continue;
					}
				}
				// 11/17/2007   On a mobile device, each new field is on a new row. 
				// 12/02/2005  COLSPAN == -1 means that a new column should not be created. 
				if ( (nCOLSPAN >= 0 && nColIndex == 0) || tr == null || bIsMobile )
				{
					// 11/25/2005   Don't pre-create a row as we don't want a blank
					// row at the bottom.  Add rows just before they are needed. 
					nRowIndex++;
					tr = new HtmlTableRow();
					tbl.Rows.Insert(nRowIndex, tr);
				}
				if ( bLayoutMode )
				{
					HtmlTableCell tdAction = new HtmlTableCell();
					tr.Cells.Add(tdAction);
					tdAction.Attributes.Add("class", "tabDetailViewDL");
					tdAction.NoWrap = true;

					Literal litIndex = new Literal();
					tdAction.Controls.Add(litIndex);
					litIndex.Text = " " + nFIELD_INDEX.ToString() + " ";

					// 05/26/2007   Fix the terms. The are in the Dropdown module. 
					// 08/24/2009   Since this is the only area where we use the ID of the dynamic view record, only get it here. 
					Guid gID = Sql.ToGuid(row["ID"]);
					// 05/18/2013   Add drag handle. 
					if ( bSupportsDraggable )
					{
						Image imgDragIcon = new Image();
						imgDragIcon.SkinID = "draghandle_table";
						imgDragIcon.Attributes.Add("draggable"  , "true");
						imgDragIcon.Attributes.Add("ondragstart", "event.dataTransfer.setData('Text', '" + nFIELD_INDEX.ToString() + "');");
						tdAction.Controls.Add(imgDragIcon);
		
						tdAction.Attributes.Add("ondragover", "LayoutDragOver(event, '" + nFIELD_INDEX.ToString() + "')");
						tdAction.Attributes.Add("ondrop"    , "LayoutDropIndex(event, '" + nFIELD_INDEX.ToString() + "')");
					}
					else
					{
						ImageButton btnMoveUp   = CreateLayoutImageButtonSkin(gID, "Layout.MoveUp"  , nFIELD_INDEX, L10n.Term("Dropdown.LNK_UP"    ), "uparrow_inline"  , Page_Command);
						ImageButton btnMoveDown = CreateLayoutImageButtonSkin(gID, "Layout.MoveDown", nFIELD_INDEX, L10n.Term("Dropdown.LNK_DOWN"  ), "downarrow_inline", Page_Command);
						tdAction.Controls.Add(btnMoveUp  );
						tdAction.Controls.Add(btnMoveDown);
					}
					ImageButton btnInsert   = CreateLayoutImageButtonSkin(gID, "Layout.Insert"  , nFIELD_INDEX, L10n.Term("Dropdown.LNK_INS"   ), "plus_inline"     , Page_Command);
					ImageButton btnEdit     = CreateLayoutImageButtonSkin(gID, "Layout.Edit"    , nFIELD_INDEX, L10n.Term("Dropdown.LNK_EDIT"  ), "edit_inline"     , Page_Command);
					ImageButton btnDelete   = CreateLayoutImageButtonSkin(gID, "Layout.Delete"  , nFIELD_INDEX, L10n.Term("Dropdown.LNK_DELETE"), "delete_inline"   , Page_Command);
					tdAction.Controls.Add(btnInsert  );
					tdAction.Controls.Add(btnEdit    );
					tdAction.Controls.Add(btnDelete  );
				}
				// 12/03/2006   Move literal label up so that it can be accessed when processing a blank. 
				Literal litLabel = new Literal();
				if ( !Sql.IsEmptyString(sDATA_FIELD) && !hashLABEL_IDs.Contains(sDATA_FIELD) )
				{
					litLabel.ID = sDATA_FIELD + "_LABEL";
					hashLABEL_IDs.Add(sDATA_FIELD, null);
				}
				// 06/20/2009   The label and the field will be on separate rows for a NewRecord form. 
				HtmlTableRow trLabel = tr;
				HtmlTableRow trField = tr;
				if ( nCOLSPAN >= 0 || tdLabel == null || tdField == null )
				{
					tdLabel = new HtmlTableCell();
					tdField = new HtmlTableCell();
					trLabel.Cells.Add(tdLabel);
					if ( sLABEL_WIDTH == "100%" && sFIELD_WIDTH == "0%" && nDATA_COLUMNS == 1 )
					{
						nRowIndex++;
						trField = new HtmlTableRow();
						tbl.Rows.Insert(nRowIndex, trField);
					}
					else
					{
						// 06/20/2009   Don't specify the normal styles for a NewRecord form. 
						// This is so that the label will be left aligned. 
						tdLabel.Attributes.Add("class", "dataLabel");
						tdLabel.VAlign = "top";
						tdLabel.Width  = sLABEL_WIDTH;
						tdField.Attributes.Add("class", "dataField");
						tdField.VAlign = "top";
					}
					trField.Cells.Add(tdField);
					if ( nCOLSPAN > 0 )
					{
						tdField.ColSpan = nCOLSPAN;
						if ( bLayoutMode )
							tdField.ColSpan++;
					}
					// 11/28/2005   Don't use the field width if COLSPAN is specified as we want it to take the rest of the table.  The label width will be sufficient. 
					if ( nCOLSPAN == 0 && sFIELD_WIDTH != "0%" )
						tdField.Width  = sFIELD_WIDTH;

					tdLabel.Controls.Add(litLabel);
					// 01/18/2010   Apply ACL Field Security. 
					litLabel.Visible = bLayoutMode || bIsReadable;
					//litLabel.Text = nFIELD_INDEX.ToString() + " (" + nRowIndex.ToString() + "," + nColIndex.ToString() + ")";
					try
					{
						// 12/03/2006   Move code to blank able in layout mode to blank section below. 
						if ( bLayoutMode )
							litLabel.Text = sDATA_LABEL;
						else if ( sDATA_LABEL.IndexOf(".") >= 0 )
							litLabel.Text = L10n.Term(sDATA_LABEL);
						else if ( !Sql.IsEmptyString(sDATA_LABEL) && rdr != null )
						{
							// 01/27/2008   If the data label is not in the schema table, then it must be free-form text. 
							// It is not used often, but we allow the label to come from the result set.  For example,
							// when the parent is stored in the record, we need to pull the module name from the record. 
							litLabel.Text = sDATA_LABEL;
							// 11/22/2010   Convert data reader to data table for Rules Wizard. 
							if ( rdr != null )
							{
								//vwSchema.RowFilter = "ColumnName = '" + Sql.EscapeSQL(sDATA_LABEL) + "'";
								//if ( vwSchema.Count > 0 )
								if ( rdr.Table.Columns.Contains(sDATA_LABEL) )
									litLabel.Text = Sql.ToString(rdr[sDATA_LABEL]) + L10n.Term("Calls.LBL_COLON");
							}
						}
						// 07/15/2006   Always put something for the label so that table borders will look right. 
						// 07/20/2007 Vandalo.  Skip the requirement to create a terminology entry and just so the label. 
						else
							litLabel.Text = sDATA_LABEL;  // "&nbsp;";

						// 06/12/2009   Add Tool Tip hover. 
						// 11/23/2009   Only add tool tip if AJAX is available and this is not a mobile device. 
						// 01/18/2010   Only add tool tip if the label is visible. 
						if ( !bIsMobile && mgrAjax != null && !Sql.IsEmptyString(sTOOL_TIP) && !Sql.IsEmptyString(sDATA_FIELD) && litLabel.Visible )
						{
							Image imgToolTip = new Image();
							imgToolTip.SkinID = "tooltip_inline";
							imgToolTip.ID     = sDATA_FIELD + "_TOOLTIP_IMAGE";
							tdLabel.Controls.Add(imgToolTip);
							
							Panel pnlToolTip = new Panel();
							pnlToolTip.ID       = sDATA_FIELD + "_TOOLTIP_PANEL";
							pnlToolTip.CssClass = "tooltip";
							tdLabel.Controls.Add(pnlToolTip);

							Literal litToolTip = new Literal();
							litToolTip.Text = sDATA_FIELD;
							pnlToolTip.Controls.Add(litToolTip);
							if ( bLayoutMode )
								litToolTip.Text = sTOOL_TIP;
							else if ( sTOOL_TIP.IndexOf(".") >= 0 )
								litToolTip.Text = L10n.Term(sTOOL_TIP);
							else
								litToolTip.Text = sTOOL_TIP;
							
							AjaxControlToolkit.HoverMenuExtender hovToolTip = new AjaxControlToolkit.HoverMenuExtender();
							hovToolTip.TargetControlID = imgToolTip.ID;
							hovToolTip.PopupControlID  = pnlToolTip.ID;
							hovToolTip.PopupPosition   = AjaxControlToolkit.HoverMenuPopupPosition.Right;
							hovToolTip.PopDelay        = 50;
							hovToolTip.OffsetX         = 0;
							hovToolTip.OffsetY         = 0;
							tdLabel.Controls.Add(hovToolTip);
						}
					}
					catch(Exception ex)
					{
						SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
						litLabel.Text = ex.Message;
					}
					if ( !bLayoutMode && bUI_REQUIRED )
					{
						Label lblRequired = new Label();
						tdLabel.Controls.Add(lblRequired);
						lblRequired.CssClass = "required";
						lblRequired.Text = L10n.Term(".LBL_REQUIRED_SYMBOL");
					}
				}
				
				if ( String.Compare(sFIELD_TYPE, "Blank", true) == 0 )
				{
					// 06/20/2009   There is no need for blank fields in a NewRecord form. 
					// By hiding them we are able to properly disable Team selection when Team Mangement is disabled. 
					if ( sLABEL_WIDTH == "100%" && sFIELD_WIDTH == "0%" && nDATA_COLUMNS == 1 )
					{
						trLabel.Visible = false;
						trField.Visible = false;
					}
					else
					{
						Literal litField = new Literal();
						tdField.Controls.Add(litField);
						if ( bLayoutMode )
						{
							litLabel.Text = "*** BLANK ***";
							litField.Text = "*** BLANK ***";
						}
						else
						{
							// 12/03/2006   Make sure to clear the label.  This is necessary to convert a TEAM to blank when disabled. 
							litLabel.Text = "&nbsp;";
							litField.Text = "&nbsp;";
						}
					}
				}
				// 09/03/2012   A separator does nothing in Layout mode. 
				else if ( String.Compare(sFIELD_TYPE, "Separator", true) == 0 )
				{
					if ( bLayoutMode )
					{
						litLabel.Text = "*** SEPARATOR ***";
						nColIndex = nDATA_COLUMNS;
						tdField.ColSpan = 2 * nDATA_COLUMNS - 1;
						// 09/03/2012   When in layout mode, we need to add a column for arrangement. 
						tdField.ColSpan++;
					}
				}
				// 09/02/2012   A header is similar to a label, but without the data field. 
				else if ( String.Compare(sFIELD_TYPE, "Header", true) == 0 )
				{
					if ( !bLayoutMode )
						litLabel.Text = "<h4>" + litLabel.Text + "</h4>";
					tdLabel.ColSpan = 2;
					tdField.Visible = false;
				}
				else if ( String.Compare(sFIELD_TYPE, "Label", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						// 05/23/2014   Use a label instead of a literal so that the field can be accessed using HTML DOM. 
						Label litField = new Label();
						tdField.Controls.Add(litField);
						// 07/25/2006   Align label values to the middle so the line-up with the label. 
						tdField.VAlign = "middle";
						// 07/24/2006   Set the ID so that the literal control can be accessed. 
						litField.ID = sDATA_FIELD;
						// 01/18/2010   Apply ACL Field Security. 
						// 10/07/2010   We need to apply ACL on each part of the label. 
						//litField.Visible = bLayoutMode || bIsReadable;
						try
						{
							if ( bLayoutMode )
								litField.Text = sDATA_FIELD;
/*
							else if ( sDATA_FIELD.IndexOf(".") >= 0 )
								litField.Text = L10n.Term(sDATA_FIELD);
							else if ( rdr != null )
								litField.Text = Sql.ToString(rdr[sDATA_FIELD]);
*/
							// 10/07/2010   Allow a label to contain multiple data entries. 
							else
							{
								string[] arrDATA_FIELD = sDATA_FIELD.Split(' ');
								object[] objDATA_FIELD = new object[arrDATA_FIELD.Length];
								for ( int i=0 ; i < arrDATA_FIELD.Length; i++ )
								{
									if ( arrDATA_FIELD[i].IndexOf(".") >= 0 )
									{
										objDATA_FIELD[i] = L10n.Term(arrDATA_FIELD[i]);
									}
									else if ( !Sql.IsEmptyString(arrDATA_FIELD[i]) )
									{
										bIsReadable = true;
										if ( SplendidInit.bEnableACLFieldSecurity )
										{
											Security.ACL_FIELD_ACCESS acl = Security.GetUserFieldSecurity(sMODULE_NAME, sDATA_FIELD, gASSIGNED_USER_ID);
											bIsReadable  = acl.IsReadable();
										}
										if ( bIsReadable && rdr != null && rdr[arrDATA_FIELD[i]] != DBNull.Value)
										{
											// 12/05/2005   If the data is a DateTime field, then make sure to perform the timezone conversion. 
											if ( rdr[arrDATA_FIELD[i]].GetType() == Type.GetType("System.DateTime") )
												objDATA_FIELD[i] = T10n.FromServerTime(rdr[arrDATA_FIELD[i]]);
											// 02/16/2010   Add MODULE_TYPE so that we can lookup custom field IDs. 
											// 02/16/2010   Move ToGuid to the function so that it can be captured if invalid. 
											else if ( !Sql.IsEmptyString(sMODULE_TYPE) )
												objDATA_FIELD[i] = Crm.Modules.ItemName(Application, sMODULE_TYPE, rdr[arrDATA_FIELD[i]]);
											else
												objDATA_FIELD[i] = rdr[arrDATA_FIELD[i]];
										}
										else
											objDATA_FIELD[i] = String.Empty;
									}
								}
								// 08/28/2012   We do not need the record to display a label. 
								//if ( rdr != null )
								{
									// 10/07/2010   There is a special case where we are show a date and a user name. 
									if ( arrDATA_FIELD.Length == 3 && objDATA_FIELD.Length == 3 && arrDATA_FIELD[1] == ".LBL_BY" && Sql.IsEmptyString(objDATA_FIELD[0]) && Sql.IsEmptyString(objDATA_FIELD[2]) )
										litField.Text = String.Empty;
									else
									// 01/09/2006   Allow DATA_FORMAT to be optional.   If missing, write data directly. 
									if ( sDATA_FORMAT == String.Empty )
									{
										for ( int i=0; i < arrDATA_FIELD.Length; i++ )
											arrDATA_FIELD[i] = Sql.ToString(objDATA_FIELD[i]);
										litField.Text = String.Join(" ", arrDATA_FIELD);
									}
									else if ( sDATA_FORMAT == "{0:c}" && C10n != null )
									{
										// 03/30/2007   Convert DetailView currencies on the fly. 
										// 05/05/2007   In an earlier step, we convert NULLs to empty strings. 
										// Attempts to convert to decimal will generate an error: Input string was not in a correct format.
										if ( !(objDATA_FIELD[0] is string) )
										{
											Decimal d = C10n.ToCurrency(Convert.ToDecimal(objDATA_FIELD[0]));
											litField.Text = d.ToString("c");
										}
									}
									else
										litField.Text = String.Format(sDATA_FORMAT, objDATA_FIELD);
								}
							}
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
							litField.Text = ex.Message;
						}
					}
				}
				// 09/13/2010   Add relationship fields. 
				else if ( String.Compare(sFIELD_TYPE, "RelatedSelect", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) && !Sql.IsEmptyString(sRELATED_SOURCE_MODULE_NAME) && bVALID_RELATED )
					{
						RelatedSelect ctlRelatedSelect = tbl.Page.LoadControl("~/_controls/RelatedSelect.ascx") as RelatedSelect;
						tdField.Controls.Add(ctlRelatedSelect);
						// 09/18/2010   Using a "." in the ID caused major AJAX failures that were hard to debug. 
						//ctlRelatedSelect.ID                           = sRELATED_VIEW_NAME + "_" + sRELATED_ID_FIELD;
						// 10/14/2011   We must use sDATA_FIELD as the ID until we can change UpdateCustomFields() to use the related ID. 
						ctlRelatedSelect.ID                           = sDATA_FIELD;
						ctlRelatedSelect.RELATED_SOURCE_MODULE_NAME   = sRELATED_SOURCE_MODULE_NAME  ;
						ctlRelatedSelect.RELATED_SOURCE_VIEW_NAME     = sRELATED_SOURCE_VIEW_NAME    ;
						ctlRelatedSelect.RELATED_SOURCE_ID_FIELD      = sRELATED_SOURCE_ID_FIELD     ;
						ctlRelatedSelect.RELATED_SOURCE_NAME_FIELD    = sRELATED_SOURCE_NAME_FIELD   ;
						ctlRelatedSelect.RELATED_VIEW_NAME            = sRELATED_VIEW_NAME           ;
						ctlRelatedSelect.RELATED_ID_FIELD             = sRELATED_ID_FIELD            ;
						ctlRelatedSelect.RELATED_NAME_FIELD           = sRELATED_NAME_FIELD          ;
						ctlRelatedSelect.RELATED_JOIN_FIELD           = sRELATED_JOIN_FIELD          ;

						ctlRelatedSelect.NotPostBack = bNotPostBack;
						ctlRelatedSelect.Visible  = bLayoutMode || bIsReadable;
						ctlRelatedSelect.Enabled  = bLayoutMode || bIsWriteable;
						try
						{
							Guid gPARENT_ID = Guid.Empty;
							if ( rdr != null )
							{
								try
								{
									gPARENT_ID = Sql.ToGuid(rdr[sDATA_FIELD]);
								}
								catch
								{
								}
							}
							ctlRelatedSelect.LoadLineItems(gPARENT_ID);
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
						}
						if ( bLayoutMode )
						{
							Literal litField = new Literal();
							litField.Text = sDATA_FIELD;
							tdField.Controls.Add(litField);
						}
					}
				}
				else if ( String.Compare(sFIELD_TYPE, "RelatedListBox", true) == 0 || String.Compare(sFIELD_TYPE, "RelatedCheckBoxList", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) && bVALID_RELATED )
					{
						ListControl lstField = new RadioButtonList();
						if ( String.Compare(sFIELD_TYPE, "RelatedListBox", true) == 0 )
						{
							lstField = new ListBox();
							(lstField as ListBox).SelectionMode = ListSelectionMode.Multiple;
							(lstField as ListBox).Rows          = (nFORMAT_ROWS == 0) ? 6 : nFORMAT_ROWS;
							tdField.Controls.Add(lstField);
						}
						else if ( String.Compare(sFIELD_TYPE, "RelatedCheckBoxList", true) == 0 )
						{
							lstField = new CheckBoxList();
							lstField.CssClass = "checkbox";
							// 09/16/2010   Put inside a div so that we can use auto-scroll. 
							if ( nFORMAT_ROWS > 0 )
							{
								HtmlGenericControl div = new HtmlGenericControl("div");
								div.Controls.Add(lstField);
								tdField.Controls.Add(div);
								div.Attributes.Add("style", "overflow-y: auto;height: " + nFORMAT_ROWS.ToString() + "px");
							}
							else
							{
								tdField.Controls.Add(lstField);
							}
						}
						else
						{
							lstField.CssClass = "radio";
							// 09/16/2010   Put inside a div so that we can use auto-scroll. 
							if ( nFORMAT_ROWS > 0 )
							{
								HtmlGenericControl div = new HtmlGenericControl("div");
								div.Controls.Add(lstField);
								tdField.Controls.Add(div);
								div.Attributes.Add("style", "overflow-y: auto;height: " + nFORMAT_ROWS.ToString() + "px");
							}
							else
							{
								tdField.Controls.Add(lstField);
							}
						}
						// 09/13/2010   We should not use the sDATA_FIELD as it might be identical for multiple RelatedListBox.  For example, it could be the ID of the record. 
						// 09/18/2010   Using a "." in the ID caused major AJAX failures that were hard to debug. 
						//lstField.ID            = sRELATED_VIEW_NAME + "_" + sRELATED_ID_FIELD;// sDATA_FIELD;
						// 10/14/2011   We must use sDATA_FIELD as the ID until we can change UpdateCustomFields() to use the related ID. 
						lstField.ID            = sDATA_FIELD;
						lstField.TabIndex      = nFORMAT_TAB_INDEX;
						lstField.Visible       = bLayoutMode || bIsReadable;
						lstField.Enabled       = bLayoutMode || bIsWriteable;
						try
						{
							// 09/13/2010   As extra precaution, make sure that the table name is valid. 
							Regex r = new Regex(@"[^A-Za-z0-9_]");
							sRELATED_SOURCE_VIEW_NAME     = r.Replace(sRELATED_SOURCE_VIEW_NAME    , "");
							sRELATED_SOURCE_ID_FIELD      = r.Replace(sRELATED_SOURCE_ID_FIELD     , "");
							sRELATED_SOURCE_NAME_FIELD    = r.Replace(sRELATED_SOURCE_NAME_FIELD   , "");
							sRELATED_VIEW_NAME            = r.Replace(sRELATED_VIEW_NAME           , "");
							sRELATED_ID_FIELD             = r.Replace(sRELATED_ID_FIELD            , "");
							sRELATED_NAME_FIELD           = r.Replace(sRELATED_NAME_FIELD          , "");
							sRELATED_JOIN_FIELD           = r.Replace(sRELATED_JOIN_FIELD          , "");

							// 09/13/2010   Add relationship fields, Don't populate list if this is a post back. 
							if ( (bLayoutMode || !bIsPostBack) )
							{
								lstField.DataValueField = sRELATED_SOURCE_ID_FIELD  ;
								lstField.DataTextField  = sRELATED_SOURCE_NAME_FIELD;
								DbProviderFactory dbf = DbProviderFactories.GetFactory();
								using ( IDbConnection con = dbf.CreateConnection() )
								{
									con.Open();
									string sSQL;
									sSQL = "select " + sRELATED_SOURCE_ID_FIELD      + ControlChars.CrLf
									     + "     , " + sRELATED_SOURCE_NAME_FIELD    + ControlChars.CrLf
									     + "  from " + sRELATED_SOURCE_VIEW_NAME     + ControlChars.CrLf
									     + " order by " + sRELATED_SOURCE_NAME_FIELD + ControlChars.CrLf;
									using ( IDbCommand cmd = con.CreateCommand() )
									{
										cmd.CommandText = sSQL;
										// 09/13/2010   When in layout mode, only fetch 10 records. 
										if ( bLayoutMode )
											Sql.LimitResults(cmd, 10);
										using ( DbDataAdapter da = dbf.CreateDataAdapter() )
										{
											((IDbDataAdapter)da).SelectCommand = cmd;
											DataTable dt = new DataTable();
											da.Fill(dt);
											lstField.DataSource = dt;
											lstField.DataBind();
										}
									}
								}
								if ( !Sql.IsEmptyString(sONCLICK_SCRIPT) )
									lstField.Attributes.Add("onchange" , sONCLICK_SCRIPT);
								// 10/02/2010   None does not seem appropriate for related data. 
								/*
								if ( !bUI_REQUIRED )
								{
									lstField.Items.Insert(0, new ListItem(L10n.Term(".LBL_NONE"), ""));
									lstField.DataBound += new EventHandler(ListControl_DataBound_AllowNull);
								}
								*/
							}
							if ( rdr != null )
							{
								try
								{
									// 10/14/2011   When settings values, there does not seem to be a good reason to do another database lookup. 
									// The lstField binding means that the values are there. 
									if ( rdr[sDATA_FIELD].GetType() == typeof(Guid) )
									{
										string sVALUE = Sql.ToGuid(rdr[sDATA_FIELD]).ToString();
										foreach ( ListItem item in lstField.Items )
										{
											if ( item.Value == sVALUE )
												item.Selected = true;
										}
									}
									else
									{
										List<string> arrVALUE = new List<string>();
										// 10/14/2011   If this is a multi-selection, then we need to get the list if values. 
										string sVALUE = Sql.ToString(rdr[sDATA_FIELD]);
										if ( sVALUE.StartsWith("<?xml") )
										{
											XmlDocument xml = new XmlDocument();
											xml.LoadXml(sVALUE);
											XmlNodeList nlValues = xml.DocumentElement.SelectNodes("Value");
											foreach ( XmlNode xValue in nlValues )
											{
												foreach ( ListItem item in lstField.Items )
												{
													if ( item.Value == xValue.InnerText )
														item.Selected = true;
												}
											}
										}
										else
										{
											foreach ( ListItem item in lstField.Items )
											{
												if ( item.Value == sVALUE )
													item.Selected = true;
											}
										}
									}
								}
								catch(Exception ex)
								{
									SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
								}
							}
							// 12/04/2005   Assigned To field will always default to the current user. 
							else if ( rdr == null && !bIsPostBack && sCACHE_NAME == "AssignedUser")
							{
								try
								{
									// 12/02/2007   We don't default the user when using multi-selection.  
									// This is because this mode is typically used for searching. 
									if ( nFORMAT_ROWS == 0 )
										// 08/19/2010   Check the list before assigning the value. 
										Utils.SetValue(lstField, Security.USER_ID.ToString());
								}
								catch(Exception ex)
								{
									SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
								}
							}
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
						}
						if ( bLayoutMode )
						{
							Literal litField = new Literal();
							litField.Text = sDATA_FIELD;
							tdField.Controls.Add(litField);
						}
					}
				}
				else if ( String.Compare(sFIELD_TYPE, "ListBox", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						// 12/02/2007   If format rows > 0 then this is a list box and not a drop down list. 
						ListControl lstField = null;
						if ( nFORMAT_ROWS > 0 )
						{
							ListBox lb = new ListBox();
							lb.SelectionMode = ListSelectionMode.Multiple;
							lb.Rows          = nFORMAT_ROWS;
							lstField = lb;
						}
						else
						{
							// 04/25/2008   Use KeySortDropDownList instead of ListSearchExtender. 
							lstField = new KeySortDropDownList();
							// 07/26/2010   Lets try the latest version of the ListSearchExtender. 
							// 07/28/2010   We are getting an undefined exception on the Accounts List Advanced page. 
							// Lets drop back to using KeySort. 
							//lstField = new DropDownList();
						}
						tdField.Controls.Add(lstField);
						lstField.ID       = sDATA_FIELD;
						lstField.TabIndex = nFORMAT_TAB_INDEX;
						// 01/18/2010   Apply ACL Field Security. 
						lstField.Visible  = bLayoutMode || bIsReadable;
						lstField.Enabled  = bLayoutMode || bIsWriteable;

						try
						{
							// 10/09/2010   Add PARENT_FIELD so that we can establish dependent listboxes. 
							if ( !Sql.IsEmptyString(sPARENT_FIELD) )
							{
								ListControl lstPARENT_FIELD = tbl.FindControl(sPARENT_FIELD) as ListControl;
								if ( lstPARENT_FIELD != null )
								{
									lstPARENT_FIELD.AutoPostBack = true;
									// 11/02/2010   We need a way to insert NONE into the a ListBox while still allowing multiple rows. 
									// The trick will be to use a negative number.  Use an absolute value here to reduce the areas to fix. 
									EditViewEventManager mgr = new EditViewEventManager(lstPARENT_FIELD, lstField, bUI_REQUIRED, Sql.ToInteger(row["FORMAT_ROWS"]), L10n);
									lstPARENT_FIELD.SelectedIndexChanged += new EventHandler(mgr.SelectedIndexChanged);
									if ( !bIsPostBack && lstPARENT_FIELD.SelectedIndex >= 0 )
									{
										sCACHE_NAME = lstPARENT_FIELD.SelectedValue;
									}
								}
							}
							// 12/04/2005   Don't populate list if this is a post back. 
							if ( !Sql.IsEmptyString(sCACHE_NAME) && (bLayoutMode || !bIsPostBack) )
							{
								// 12/24/2007   Use an array to define the custom caches so that list is in the Cache module. 
								// This should reduce the number of times that we have to edit the SplendidDynamic module. 
								// 02/16/2012   Move custom cache logic to a method. 
								SplendidCache.SetListSource(sCACHE_NAME, lstField);
								lstField.DataBind();
								// 08/08/2006   Allow onchange code to be stored in the database.  
								// ListBoxes do not have a useful onclick event, so there should be no problem overloading this field. 
								if ( !Sql.IsEmptyString(sONCLICK_SCRIPT) )
									lstField.Attributes.Add("onchange" , sONCLICK_SCRIPT);
								// 02/21/2006   Move the NONE item inside the !IsPostBack code. 
								// 12/02/2007   We don't need a NONE record when using multi-selection. 
								// 12/03/2007   We do want the NONE record when using multi-selection. 
								// This will allow searching of fields that are null instead of using the unassigned only checkbox. 
								// 10/02/2010   It does not seem logical to allow a NONE option on a multi-selection listbox. 
								// 11/02/2010   We need a way to insert NONE into the a ListBox while still allowing multiple rows. 
								// The trick will be to use a negative number.  Use an absolute value here to reduce the areas to fix. 
								if ( !bUI_REQUIRED && Sql.ToInteger(row["FORMAT_ROWS"]) <= 0 )
								{
                                    lstField.Items.Insert(0, new ListItem("--È«²¿--",""));

                                    /*
									lstField.Items.Insert(0, new ListItem(L10n.Term(".LBL_NONE"), ""));
									// 12/02/2007   AppendEditViewFields should be called inside Page_Load when not a postback, 
									// and in InitializeComponent when it is a postback. If done wrong, 
									// the page will bind after the list is populated, causing the list to populate again. 
									// This event will cause the NONE entry to be cleared.  Add a handler to catch this problem, 
									// but the real solution is to call AppendEditViewFields at the appropriate times based on the postback event. 
									lstField.DataBound += new EventHandler(ListControl_DataBound_AllowNull);
                                     */
								}
								// 01/20/2010   Set the default value for Currencies. 
								if ( !bLayoutMode && rdr == null && !bIsPostBack && sCACHE_NAME == "Currencies" )
								{
									try
									{
										Guid gCURRENCY_ID = Sql.ToGuid(HttpContext.Current.Session["USER_SETTINGS/CURRENCY"]);
										// 08/19/2010   Check the list before assigning the value. 
										Utils.SetValue(lstField, gCURRENCY_ID.ToString());
									}
									catch
									{
									}
								}
							}
							if ( rdr != null )
							{
								try
								{
									// 02/21/2006   All the DropDownLists in the Calls and Meetings edit views were not getting set.  
									// The problem was a Page.DataBind in the SchedulingGrid and in the InviteesView. Both binds needed to be removed. 
									// 12/30/2007   A customer needed the ability to save and restore the multiple selection. 
									// 12/30/2007   Require the XML declaration in the data before trying to treat as XML. 
									string sVALUE = Sql.ToString(rdr[sDATA_FIELD]);
									if ( nFORMAT_ROWS > 0 && sVALUE.StartsWith("<?xml") )
									{
										XmlDocument xml = new XmlDocument();
										xml.LoadXml(sVALUE);
										XmlNodeList nlValues = xml.DocumentElement.SelectNodes("Value");
										foreach ( XmlNode xValue in nlValues )
										{
											foreach ( ListItem item in lstField.Items )
											{
												if ( item.Value == xValue.InnerText )
													item.Selected = true;
											}
										}
									}
									else
									{
										// 08/19/2010   Check the list before assigning the value. 
										Utils.SetValue(lstField, sVALUE);
									}
								}
								catch(Exception ex)
								{
									SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
								}
							}
							// 12/04/2005   Assigned To field will always default to the current user. 
							else if ( rdr == null && !bIsPostBack && sCACHE_NAME == "AssignedUser")
							{
								try
								{
									// 12/02/2007   We don't default the user when using multi-selection.  
									// This is because this mode is typically used for searching. 
									if ( nFORMAT_ROWS == 0 )
										// 08/19/2010   Check the list before assigning the value. 
										Utils.SetValue(lstField, Security.USER_ID.ToString());
								}
								catch(Exception ex)
								{
									SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
								}
							}
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
						}
						if ( bLayoutMode )
						{
							Literal litField = new Literal();
							litField.Text = sDATA_FIELD;
							tdField.Controls.Add(litField);
						}
					}
				}
				// 06/16/2010   Add support for CheckBoxList. 
				else if ( String.Compare(sFIELD_TYPE, "CheckBoxList", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						// 12/02/2007   If format rows > 0 then this is a list box and not a drop down list. 
						ListControl lstField = new CheckBoxList();
						// 09/16/2010   Put inside a div so that we can use auto-scroll. 
						if ( nFORMAT_ROWS > 0 )
						{
							HtmlGenericControl div = new HtmlGenericControl("div");
							div.Controls.Add(lstField);
							tdField.Controls.Add(div);
							div.Attributes.Add("style", "overflow-y: auto;height: " + nFORMAT_ROWS.ToString() + "px");
						}
						else
						{
							tdField.Controls.Add(lstField);
						}
						lstField.ID       = sDATA_FIELD;
						lstField.TabIndex = nFORMAT_TAB_INDEX;
						lstField.CssClass = "checkbox";
						// 01/18/2010   Apply ACL Field Security. 
						lstField.Visible  = bLayoutMode || bIsReadable;
						lstField.Enabled  = bLayoutMode || bIsWriteable;
						// 03/22/2013   Allow horizontal CheckBoxList. 
						if ( sDATA_FORMAT == "1" )
						{
							(lstField as CheckBoxList).RepeatDirection = System.Web.UI.WebControls.RepeatDirection.Horizontal;
							(lstField as CheckBoxList).RepeatLayout    = System.Web.UI.WebControls.RepeatLayout.Flow;
						}
						try
						{
							if ( !Sql.IsEmptyString(sDATA_FIELD) )
							{
								// 12/04/2005   Don't populate list if this is a post back. 
								if ( !Sql.IsEmptyString(sCACHE_NAME) && (bLayoutMode || !bIsPostBack) )
								{
									// 12/24/2007   Use an array to define the custom caches so that list is in the Cache module. 
									// This should reduce the number of times that we have to edit the SplendidDynamic module. 
									// 02/16/2012   Move custom cache logic to a method. 
									SplendidCache.SetListSource(sCACHE_NAME, lstField);
									lstField.DataBind();
								}
								if ( rdr != null )
								{
									try
									{
										string sVALUE = Sql.ToString(rdr[sDATA_FIELD]);
										if ( sVALUE.StartsWith("<?xml") )
										{
											XmlDocument xml = new XmlDocument();
											xml.LoadXml(sVALUE);
											XmlNodeList nlValues = xml.DocumentElement.SelectNodes("Value");
											foreach ( XmlNode xValue in nlValues )
											{
												foreach ( ListItem item in lstField.Items )
												{
													if ( item.Value == xValue.InnerText )
														item.Selected = true;
												}
											}
										}
										// 03/22/2013   REPEAT_DOW is a special list that returns 0 = sunday, 1 = monday, etc. 
										else if ( sDATA_FIELD == "REPEAT_DOW" )
										{
											for ( int i = 0; i < lstField.Items.Count; i++ )
											{
												if ( sVALUE.Contains(i.ToString()) )
													lstField.Items[i].Selected = true;
											}
										}
										else
										{
											// 08/19/2010   Check the list before assigning the value. 
											Utils.SetValue(lstField, sVALUE);
										}
									}
									catch(Exception ex)
									{
										SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
									}
								}
								// 12/04/2005   Assigned To field will always default to the current user. 
								else if ( rdr == null && !bIsPostBack && sCACHE_NAME == "AssignedUser")
								{
									try
									{
										// 08/19/2010   Check the list before assigning the value. 
										Utils.SetValue(lstField, Security.USER_ID.ToString());
									}
									catch(Exception ex)
									{
										SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
									}
								}
							}
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
						}
						if ( bLayoutMode )
						{
							Literal litField = new Literal();
							litField.Text = sDATA_FIELD;
							tdField.Controls.Add(litField);
						}
					}
				}
				// 06/16/2010   Add support for Radio buttons. 
				else if ( String.Compare(sFIELD_TYPE, "Radio", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						ListControl lstField = new RadioButtonList();
						// 09/16/2010   Put inside a div so that we can use auto-scroll. 
						if ( nFORMAT_ROWS > 0 )
						{
							HtmlGenericControl div = new HtmlGenericControl("div");
							div.Controls.Add(lstField);
							tdField.Controls.Add(div);
							div.Attributes.Add("style", "overflow-y: auto;height: " + nFORMAT_ROWS.ToString() + "px");
						}
						else
						{
							tdField.Controls.Add(lstField);
						}
						lstField.ID       = sDATA_FIELD;
						lstField.TabIndex = nFORMAT_TAB_INDEX;
						lstField.CssClass = "radio";
						// 01/18/2010   Apply ACL Field Security. 
						lstField.Visible  = bLayoutMode || bIsReadable;
						lstField.Enabled  = bLayoutMode || bIsWriteable;
						try
						{
							if ( !Sql.IsEmptyString(sDATA_FIELD) )
							{
								// 12/04/2005   Don't populate list if this is a post back. 
								if ( !Sql.IsEmptyString(sCACHE_NAME) && (bLayoutMode || !bIsPostBack) )
								{
									// 12/24/2007   Use an array to define the custom caches so that list is in the Cache module. 
									// This should reduce the number of times that we have to edit the SplendidDynamic module. 
									// 02/16/2012   Move custom cache logic to a method. 
									SplendidCache.SetListSource(sCACHE_NAME, lstField);
									lstField.DataBind();
									// 08/08/2006   Allow onchange code to be stored in the database.  
									// ListBoxes do not have a useful onclick event, so there should be no problem overloading this field. 
									if ( !Sql.IsEmptyString(sONCLICK_SCRIPT) )
										lstField.Attributes.Add("onchange" , sONCLICK_SCRIPT);
									// 02/21/2006   Move the NONE item inside the !IsPostBack code. 
									// 12/02/2007   We don't need a NONE record when using multi-selection. 
									// 12/03/2007   We do want the NONE record when using multi-selection. 
									// This will allow searching of fields that are null instead of using the unassigned only checkbox. 
									if ( !bUI_REQUIRED )
									{
										lstField.Items.Insert(0, new ListItem(L10n.Term(".LBL_NONE"), ""));
										// 12/02/2007   AppendEditViewFields should be called inside Page_Load when not a postback, 
										// and in InitializeComponent when it is a postback. If done wrong, 
										// the page will bind after the list is populated, causing the list to populate again. 
										// This event will cause the NONE entry to be cleared.  Add a handler to catch this problem, 
										// but the real solution is to call AppendEditViewFields at the appropriate times based on the postback event. 
										lstField.DataBound += new EventHandler(ListControl_DataBound_AllowNull);
									}
									else
									{
										// 06/16/2010   If the UI is required for Radio buttons, then we need to set the first item. 
										if ( !bIsPostBack && rdr == null )
										{
											lstField.SelectedIndex = 0;
										}
									}
									// 01/20/2010   Set the default value for Currencies. 
									if ( !bLayoutMode && rdr == null && !bIsPostBack && sCACHE_NAME == "Currencies" )
									{
										try
										{
											Guid gCURRENCY_ID = Sql.ToGuid(HttpContext.Current.Session["USER_SETTINGS/CURRENCY"]);
											// 08/19/2010   Check the list before assigning the value. 
											Utils.SetValue(lstField, gCURRENCY_ID.ToString());
										}
										catch
										{
										}
									}
								}
								if ( rdr != null )
								{
									try
									{
										// 02/21/2006   All the DropDownLists in the Calls and Meetings edit views were not getting set.  
										// The problem was a Page.DataBind in the SchedulingGrid and in the InviteesView. Both binds needed to be removed. 
										// 12/30/2007   A customer needed the ability to save and restore the multiple selection. 
										// 12/30/2007   Require the XML declaration in the data before trying to treat as XML. 
										string sVALUE = Sql.ToString(rdr[sDATA_FIELD]);
										if ( nFORMAT_ROWS > 0 && sVALUE.StartsWith("<?xml") )
										{
											XmlDocument xml = new XmlDocument();
											xml.LoadXml(sVALUE);
											XmlNodeList nlValues = xml.DocumentElement.SelectNodes("Value");
											foreach ( XmlNode xValue in nlValues )
											{
												foreach ( ListItem item in lstField.Items )
												{
													if ( item.Value == xValue.InnerText )
														item.Selected = true;
												}
											}
										}
										else
										{
											// 08/19/2010   Check the list before assigning the value. 
											Utils.SetValue(lstField, sVALUE);
										}
									}
									catch(Exception ex)
									{
										SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
									}
								}
								// 12/04/2005   Assigned To field will always default to the current user. 
								else if ( rdr == null && !bIsPostBack && sCACHE_NAME == "AssignedUser")
								{
									try
									{
										// 12/02/2007   We don't default the user when using multi-selection.  
										// This is because this mode is typically used for searching. 
										if ( nFORMAT_ROWS == 0 )
											// 08/19/2010   Check the list before assigning the value. 
											Utils.SetValue(lstField, Security.USER_ID.ToString());
									}
									catch(Exception ex)
									{
										SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
									}
								}
							}
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
						}
						if ( bLayoutMode )
						{
							Literal litField = new Literal();
							litField.Text = sDATA_FIELD;
							tdField.Controls.Add(litField);
						}
					}
				}
				else if ( String.Compare(sFIELD_TYPE, "CheckBox", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						CheckBox chkField = new CheckBox();
						tdField.Controls.Add(chkField);
						chkField.ID = sDATA_FIELD;
						chkField.CssClass = "checkbox";
						chkField.TabIndex = nFORMAT_TAB_INDEX;
						// 01/18/2010   Apply ACL Field Security. 
						chkField.Visible  = bLayoutMode || bIsReadable;
						chkField.Enabled  = bLayoutMode || bIsWriteable;
						try
						{
							if ( rdr != null )
								chkField.Checked = Sql.ToBoolean(rdr[sDATA_FIELD]);
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
						}
						// 07/11/2007   A checkbox can have a click event. 
						if ( !Sql.IsEmptyString(sONCLICK_SCRIPT) )
							chkField.Attributes.Add("onclick", sONCLICK_SCRIPT);
						if ( bLayoutMode )
						{
							Literal litField = new Literal();
							litField.Text = sDATA_FIELD;
							tdField.Controls.Add(litField);
							chkField.Enabled  = false     ;
						}
					}
				}
				else if ( String.Compare(sFIELD_TYPE, "ChangeButton", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						//05/06/2010   Manually generate ClearModuleType so that it will be UpdatePanel safe. 
						DropDownList lstField = null;
						// 12/04/2005   If the label is PARENT_TYPE, then change the label to a DropDownList.
						if ( sDATA_LABEL == "PARENT_TYPE" )
						{
							tdLabel.Controls.Clear();
							// 04/25/2008   Use KeySortDropDownList instead of ListSearchExtender. 
							// 01/13/2010   KeySortDropDownList is causing OnChange will always fire when tabbed-away. 
							// For the Parent DropDownList, we don't need the KeySort as it is a short list. 
							//DropDownList lstField = new KeySortDropDownList();
							lstField = new DropDownList();
							tdLabel.Controls.Add(lstField);
							// 11/11/2010   Give the parent type a unique name. 
							// 02/04/2011   We gave the PARENT_TYPE a unique name, but we need to update all EditViews and NewRecords. 
							lstField.ID       = sDATA_FIELD + "_PARENT_TYPE";
							lstField.TabIndex = nFORMAT_TAB_INDEX;
							// 04/02/2013   Apply ACL Field Security to Parent Type field. 
							if ( SplendidInit.bEnableACLFieldSecurity )
							{
								Security.ACL_FIELD_ACCESS acl = Security.GetUserFieldSecurity(sMODULE_NAME, "PARENT_TYPE", gASSIGNED_USER_ID);
								lstField.Visible  = bLayoutMode || acl.IsReadable();
								lstField.Enabled  = bLayoutMode || acl.IsWriteable() || sEDIT_NAME.Contains(".Search");
							}
							
							
							// 04/25/2008   Add AJAX searching of list. 
							// 04/25/2008   ListSearchExtender needs work.  I don't like the delay when a list is selected
							// and there are problems when the browser window is scrolled.  KeySortDropDownList is a better solution. 
							// 07/23/2010   Lets try the latest version of the ListSearchExtender. 
							// 07/28/2010   We are getting an undefined exception on the Accounts List Advanced page. 
							/*
							AjaxControlToolkit.ListSearchExtender extField = new AjaxControlToolkit.ListSearchExtender();
							extField.ID              = lstField.ID + "_ListSearchExtender";
							extField.TargetControlID = lstField.ID;
							extField.PromptText      = L10n.Term(".LBL_TYPE_TO_SEARCH");
							extField.PromptCssClass  = "ListSearchExtenderPrompt";
							tdLabel.Controls.Add(extField);
							*/
							if ( bLayoutMode || !bIsPostBack )
							{
								// 07/29/2005   SugarCRM 3.0 does not allow the NONE option. 
								lstField.DataValueField = "NAME"        ;
								lstField.DataTextField  = "DISPLAY_NAME";
								lstField.DataSource     = SplendidCache.List("record_type_display");
								lstField.DataBind();
								if ( rdr != null )
								{
									try
									{
										// 08/19/2010   Check the list before assigning the value. 
										Utils.SetValue(lstField, Sql.ToString(rdr[sDATA_LABEL]));
									}
									catch(Exception ex)
									{
										SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
									}
								}
							}
						}
						TextBox txtNAME = new TextBox();
						tdField.Controls.Add(txtNAME);
						txtNAME.ID       = sDISPLAY_FIELD;
						txtNAME.ReadOnly = true;
						txtNAME.TabIndex = nFORMAT_TAB_INDEX;
						// 11/25/2006    Turn off viewstate so that we can fix the text on postback. 
						txtNAME.EnableViewState = false;
						// 01/18/2010   Apply ACL Field Security. 
						txtNAME.Visible  = bLayoutMode || bIsReadable;
						txtNAME.Enabled  = bLayoutMode || bIsWriteable;
						try
						{
							if ( bLayoutMode )
							{
								txtNAME.Text    = sDISPLAY_FIELD;
								txtNAME.Enabled = false         ;
							}
							// 11/25/2006   The Change text field is losing its value during a postback error. 
							else if ( bIsPostBack )
							{
								// 11/25/2006   In order for this posback fix to work, viewstate must be disabled for this field. 
								if ( tbl.Page.Request[txtNAME.UniqueID] != null )
									txtNAME.Text = Sql.ToString(tbl.Page.Request[txtNAME.UniqueID]);
							}
							else if ( !Sql.IsEmptyString(sDISPLAY_FIELD) && rdr != null )
								txtNAME.Text = Sql.ToString(rdr[sDISPLAY_FIELD]);
							// 11/25/2006   The team name should always default to the current user's private team. 
							// Make sure not to overwrite the value if this is a postback. 
							// 08/26/2009   Don't prepopulate team or user if in a search dialog. 
							else if ( sEDIT_NAME.IndexOf(".Search") < 0 && sDATA_FIELD == "TEAM_ID" && rdr == null && !bIsPostBack )
								txtNAME.Text = Security.TEAM_NAME;
							// 01/15/2007   Assigned To field will always default to the current user. 
							else if ( sEDIT_NAME.IndexOf(".Search") < 0 && sDATA_FIELD == "ASSIGNED_USER_ID" && rdr == null && !bIsPostBack )
							{
								// 01/29/2011   If Full Names have been enabled, then prepopulate with the full name. 
								if ( sDISPLAY_FIELD == "ASSIGNED_TO_NAME" )
									txtNAME.Text = Security.FULL_NAME;
								else
									txtNAME.Text = Security.USER_NAME;
							}
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
							txtNAME.Text = ex.Message;
						}
						HtmlInputHidden hidID = new HtmlInputHidden();
						tdField.Controls.Add(hidID);
						hidID.ID = sDATA_FIELD;
						try
						{
							if ( !bLayoutMode )
							{
								if ( !Sql.IsEmptyString(sDATA_FIELD) && rdr != null )
									hidID.Value = Sql.ToString(rdr[sDATA_FIELD]);
								// 11/25/2006   The team name should always default to the current user's private team. 
								// Make sure not to overwrite the value if this is a postback. 
								// The hidden field does not require the same viewstate fix as the txtNAME field. 
								// 04/23/2009   Make sure not to initialize the field with an empty guid as that will prevent the required field notice. 
								// 08/26/2009   Don't prepopulate team or user if in a search dialog. 
								else if ( sEDIT_NAME.IndexOf(".Search") < 0 && sDATA_FIELD == "TEAM_ID" && rdr == null && !bIsPostBack && !Sql.IsEmptyGuid(Security.TEAM_ID) )
									hidID.Value = Security.TEAM_ID.ToString();
								// 01/15/2007   Assigned To field will always default to the current user. 
								else if ( sEDIT_NAME.IndexOf(".Search") < 0 && sDATA_FIELD == "ASSIGNED_USER_ID" && rdr == null && !bIsPostBack )
									hidID.Value = Security.USER_ID.ToString();
							}
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
							txtNAME.Text = ex.Message;
						}
						//05/06/2010   Manually generate ClearModuleType so that it will be UpdatePanel safe. 
						// 07/27/2010   Add the ability to submit after clear. 
						if ( sDATA_LABEL == "PARENT_TYPE" && lstField != null )
							lstField.Attributes.Add("onChange", "ClearModuleType('', '" + hidID.ClientID + "', '" + txtNAME.ClientID + "', false);");
						
						Literal litNBSP = new Literal();
						tdField.Controls.Add(litNBSP);
						litNBSP.Text = "&nbsp;";
						
						// 06/20/2009   The Select button will go on a separate row in the NewRecord form. 
						if ( sLABEL_WIDTH == "100%" && sFIELD_WIDTH == "0%" && nDATA_COLUMNS == 1 )
						{
							nRowIndex++;
							trField = new HtmlTableRow();
							tbl.Rows.Insert(nRowIndex, trField);
							tdField = new HtmlTableCell();
							trField.Cells.Add(tdField);
						}
						HtmlInputButton btnChange = new HtmlInputButton("button");
						tdField.Controls.Add(btnChange);
						// 05/07/2006   Specify a name for the check button so that it can be referenced by SplendidTest. 
						btnChange.ID = sDATA_FIELD + "_btnChange";
						btnChange.Attributes.Add("class", "button");
						// 05/06/2010   Manually generate ParentPopup so that it will be UpdatePanel safe. 
						// 07/27/2010   Use the DATA_FORMAT field to determine if the ModulePopup will auto-submit. 
						string[] arrDATA_FORMAT = sDATA_FORMAT.Split(',');
						if ( lstField != null )
						{
							btnChange.Attributes.Add("onclick", "return ModulePopup(document.getElementById('" + lstField.ClientID + "').options[document.getElementById('" + lstField.ClientID + "').options.selectedIndex].value, '" + hidID.ClientID + "', '" + txtNAME.ClientID + "', null, " + (arrDATA_FORMAT[0] == "1" ? "true" : "false") + ", null);");
						}
						else if ( !Sql.IsEmptyString(sONCLICK_SCRIPT) )
							btnChange.Attributes.Add("onclick"  , sONCLICK_SCRIPT);
						// 03/31/2007   SugarCRM now uses Select instead of Change. 
						btnChange.Attributes.Add("title"    , L10n.Term(".LBL_SELECT_BUTTON_TITLE"));
						// 07/31/2006   Stop using VisualBasic library to increase compatibility with Mono. 
						// 03/31/2007   Stop using AccessKey for change button. 
						//btnChange.Attributes.Add("accessKey", L10n.Term(".LBL_SELECT_BUTTON_KEY").Substring(0, 1));
						btnChange.Value = L10n.Term(".LBL_SELECT_BUTTON_LABEL");
						// 01/18/2010   Apply ACL Field Security. 
						btnChange.Visible  =   bLayoutMode || bIsReadable;
						btnChange.Disabled = !(bLayoutMode || bIsWriteable);

						// 12/03/2007   Also create a Clear button. 
						// 05/06/2010   A Parent Type will always have a clear button. 
						if ( sONCLICK_SCRIPT.IndexOf("Popup();") > 0 || sDATA_LABEL == "PARENT_TYPE" )
						{
							litNBSP = new Literal();
							tdField.Controls.Add(litNBSP);
							litNBSP.Text = "&nbsp;";
							
							HtmlInputButton btnClear = new HtmlInputButton("button");
							tdField.Controls.Add(btnClear);
							btnClear.ID = sDATA_FIELD + "_btnClear";
							btnClear.Attributes.Add("class", "button");
							// 05/06/2010   Manually generate ClearModuleType so that it will be UpdatePanel safe. 
							// 07/27/2010   Add the ability to submit after clear. 
							btnClear.Attributes.Add("onclick"  , "return ClearModuleType('', '" + hidID.ClientID + "', '" + txtNAME.ClientID + "', " + (arrDATA_FORMAT[0] == "1" ? "true" : "false") + ");");
							btnClear.Attributes.Add("title"    , L10n.Term(".LBL_CLEAR_BUTTON_TITLE"));
							btnClear.Value = L10n.Term(".LBL_CLEAR_BUTTON_LABEL");
							// 01/18/2010   Apply ACL Field Security. 
							btnClear.Visible  =   bLayoutMode || bIsReadable;
							btnClear.Disabled = !(bLayoutMode || bIsWriteable);
						}
						// 11/11/2010   Always create the Required Field Validator so that we can Enable/Disable in a Rule. 
						if ( !bLayoutMode && /* bUI_REQUIRED && */ !Sql.IsEmptyString(sDATA_FIELD) )
						{
							RequiredFieldValidatorForHiddenInputs reqID = new RequiredFieldValidatorForHiddenInputs();
							reqID.ID                 = sDATA_FIELD + "_REQUIRED";
							reqID.ControlToValidate  = hidID.ID;
							reqID.ErrorMessage       = L10n.Term(".ERR_REQUIRED_FIELD");
							reqID.CssClass           = "required";
							reqID.EnableViewState    = false;
							// 01/16/2006   We don't enable required fields until we attempt to save. 
							// This is to allow unrelated form actions; the Cancel button is a good example. 
							reqID.EnableClientScript = false;
							reqID.Enabled            = false;
							// 02/21/2008   Add a little padding. 
							reqID.Style.Add("padding-left", "4px");
							tdField.Controls.Add(reqID);
						}
					}
				}
				// 05/17/2009   Add support for a generic module popup. 
				else if ( String.Compare(sFIELD_TYPE, "ModulePopup", true) == 0 )
				{
					//12/07/2009   For cell phones that do not support popups, convert to a DropDownList. 
					if ( !Sql.IsEmptyString(sDATA_FIELD) && !bSupportsPopups )
					{
						ListControl lstField = new DropDownList();
						tdField.Controls.Add(lstField);
						lstField.ID       = sDATA_FIELD;
						lstField.TabIndex = nFORMAT_TAB_INDEX;
						// 01/18/2010   Apply ACL Field Security. 
						lstField.Visible  = bLayoutMode || bIsReadable;
						lstField.Enabled  = bLayoutMode || bIsWriteable;
						try
						{
							// 12/04/2005   Don't populate list if this is a post back. 
							if ( (bLayoutMode || !bIsPostBack) )
							{
								try
								{
									using ( DataTable dt = Crm.Modules.Items(sMODULE_TYPE) )
									{
										lstField.DataValueField = "ID"  ;
										lstField.DataTextField  = "NAME";
										lstField.DataSource     = dt;
										lstField.DataBind();
									}
								}
								catch(Exception ex)
								{
									SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
								}
								if ( !bUI_REQUIRED )
								{
									lstField.Items.Insert(0, new ListItem(L10n.Term(".LBL_NONE"), ""));
									// 12/02/2007   AppendEditViewFields should be called inside Page_Load when not a postback, 
									// and in InitializeComponent when it is a postback. If done wrong, 
									// the page will bind after the list is populated, causing the list to populate again. 
									// This event will cause the NONE entry to be cleared.  Add a handler to catch this problem, 
									// but the real solution is to call AppendEditViewFields at the appropriate times based on the postback event. 
									lstField.DataBound += new EventHandler(ListControl_DataBound_AllowNull);
								}
							}
							if ( rdr != null )
							{
								// 08/19/2010   Check the list before assigning the value. 
								Utils.SetValue(lstField, Sql.ToGuid(rdr[sDATA_FIELD]).ToString());
							}
							else if ( sEDIT_NAME.IndexOf(".Search") < 0 && sDATA_FIELD == "ASSIGNED_USER_ID" && rdr == null && !bIsPostBack )
							{
								// 08/19/2010   Check the list before assigning the value. 
								Utils.SetValue(lstField, Security.USER_ID.ToString());
							}
							else if ( sEDIT_NAME.IndexOf(".Search") < 0 && sDATA_FIELD == "TEAM_ID" && rdr == null && !bIsPostBack )
							{
								// 08/19/2010   Check the list before assigning the value. 
								Utils.SetValue(lstField, Security.TEAM_ID.ToString());
							}
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
						}
					}
					else if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						TextBox txtNAME = new TextBox();
						tdField.Controls.Add(txtNAME);
						// 10/05/2010   A custom field will not have a display field, but we still want to be able to access by name. 
						txtNAME.ID       = Sql.IsEmptyString(sDISPLAY_FIELD) ? sDATA_FIELD + "_NAME" : sDISPLAY_FIELD;
						txtNAME.ReadOnly = true;
						txtNAME.TabIndex = nFORMAT_TAB_INDEX;
						// 11/25/2006    Turn off viewstate so that we can fix the text on postback. 
						txtNAME.EnableViewState = false;
						// 01/18/2010   Apply ACL Field Security. 
						txtNAME.Visible  = bLayoutMode || bIsReadable;
						txtNAME.Enabled  = bLayoutMode || bIsWriteable;
						try
						{
							if ( bLayoutMode )
							{
								txtNAME.Text    = sDISPLAY_FIELD;
								txtNAME.Enabled = false         ;
							}
							// 11/25/2006   The Change text field is losing its value during a postback error. 
							else if ( bIsPostBack )
							{
								// 11/25/2006   In order for this posback fix to work, viewstate must be disabled for this field. 
								if ( tbl.Page.Request[txtNAME.UniqueID] != null )
									txtNAME.Text = Sql.ToString(tbl.Page.Request[txtNAME.UniqueID]);
							}
							else if ( rdr != null )
							{
								// 12/03/2009   We must use vwSchema to look for the desired column name. 
								// 11/22/2010   Convert data reader to data table for Rules Wizard. 
								//if ( vwSchema != null )
								//	vwSchema.RowFilter = "ColumnName = '" + Sql.EscapeSQL(sDISPLAY_FIELD) + "'";
								if ( !Sql.IsEmptyString(sDISPLAY_FIELD) && row != null && rdr.Table.Columns.Contains(sDISPLAY_FIELD) )
									txtNAME.Text = Sql.ToString(rdr[sDISPLAY_FIELD]);
								else
								{
									// 02/16/2010   Move ToGuid to the function so that it can be captured if invalid. 
									txtNAME.Text = Crm.Modules.ItemName(Application, sMODULE_TYPE, rdr[sDATA_FIELD]);
								}
							}
							// 11/25/2006   The team name should always default to the current user's private team. 
							// Make sure not to overwrite the value if this is a postback. 
							// 08/26/2009   Don't prepopulate team or user if in a search dialog. 
							else if ( sEDIT_NAME.IndexOf(".Search") < 0 && sDATA_FIELD == "TEAM_ID" && rdr == null && !bIsPostBack )
								txtNAME.Text = Security.TEAM_NAME;
							// 01/15/2007   Assigned To field will always default to the current user. 
							else if ( sEDIT_NAME.IndexOf(".Search") < 0 && sDATA_FIELD == "ASSIGNED_USER_ID" && rdr == null && !bIsPostBack )
							{
								// 01/29/2011   If Full Names have been enabled, then prepopulate with the full name. 
								if ( sDISPLAY_FIELD == "ASSIGNED_TO_NAME" )
									txtNAME.Text = Security.FULL_NAME;
								else
									txtNAME.Text = Security.USER_NAME;
							}
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
							txtNAME.Text = ex.Message;
						}
						HtmlInputHidden hidID = new HtmlInputHidden();
						tdField.Controls.Add(hidID);
						hidID.ID = sDATA_FIELD;
						try
						{
							if ( !bLayoutMode )
							{
								if ( !Sql.IsEmptyString(sDATA_FIELD) && rdr != null )
									hidID.Value = Sql.ToString(rdr[sDATA_FIELD]);
								// 11/25/2006   The team name should always default to the current user's private team. 
								// Make sure not to overwrite the value if this is a postback. 
								// The hidden field does not require the same viewstate fix as the txtNAME field. 
								// 04/23/2009   Make sure not to initialize the field with an empty guid as that will prevent the required field notice. 
								// 08/26/2009   Don't prepopulate team or user if in a search dialog. 
								else if ( sEDIT_NAME.IndexOf(".Search") < 0 && sDATA_FIELD == "TEAM_ID" && rdr == null && !bIsPostBack && !Sql.IsEmptyGuid(Security.TEAM_ID) )
									hidID.Value = Security.TEAM_ID.ToString();
								// 01/15/2007   Assigned To field will always default to the current user. 
								else if ( sEDIT_NAME.IndexOf(".Search") < 0 && sDATA_FIELD == "ASSIGNED_USER_ID" && rdr == null && !bIsPostBack )
									hidID.Value = Security.USER_ID.ToString();
							}
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
							txtNAME.Text = ex.Message;
						}
						
						Literal litNBSP = new Literal();
						tdField.Controls.Add(litNBSP);
						litNBSP.Text = "&nbsp;";
						
						// 06/20/2009   The Select button will go on a separate row in the NewRecord form. 
						if ( sLABEL_WIDTH == "100%" && sFIELD_WIDTH == "0%" && nDATA_COLUMNS == 1 )
						{
							nRowIndex++;
							trField = new HtmlTableRow();
							tbl.Rows.Insert(nRowIndex, trField);
							tdField = new HtmlTableCell();
							trField.Cells.Add(tdField);
						}
						HtmlInputButton btnChange = new HtmlInputButton("button");
						tdField.Controls.Add(btnChange);
						// 05/07/2006   Specify a name for the check button so that it can be referenced by SplendidTest. 
						btnChange.ID = sDATA_FIELD + "_btnChange";
						btnChange.Attributes.Add("class", "button");
						// 07/27/2010   We need to allow an onclick to override the default ModulePopup behavior. 
						string[] arrDATA_FORMAT = sDATA_FORMAT.Split(',');
						if ( !Sql.IsEmptyString(sONCLICK_SCRIPT) )
							btnChange.Attributes.Add("onclick"  , sONCLICK_SCRIPT);
						else
						{
							// 08/01/2010   We need to tell the Users popup to return the FULL NAME. 
							string sQUERY = "null";
							if ( sMODULE_TYPE == "Users" && sDISPLAY_FIELD == "ASSIGNED_TO_NAME" )
								sQUERY = "'FULL_NAME=1'";  // 08/01/201   Query must be quoted. 
							// 07/27/2010   Use the DATA_FORMAT field to determine if the ModulePopup will auto-submit. 
							btnChange.Attributes.Add("onclick"  , "return ModulePopup('" + sMODULE_TYPE + "', '" + hidID.ClientID + "', '" + txtNAME.ClientID + "', " + sQUERY + ", " + (arrDATA_FORMAT[0] == "1" ? "true" : "false") + ", null);");
						}
						// 03/31/2007   SugarCRM now uses Select instead of Change. 
						btnChange.Attributes.Add("title"    , L10n.Term(".LBL_SELECT_BUTTON_TITLE"));
						btnChange.Value = L10n.Term(".LBL_SELECT_BUTTON_LABEL");
						// 01/18/2010   Apply ACL Field Security. 
						btnChange.Visible  =   bLayoutMode || bIsReadable;
						btnChange.Disabled = !(bLayoutMode || bIsWriteable);
						
						litNBSP = new Literal();
						tdField.Controls.Add(litNBSP);
						litNBSP.Text = "&nbsp;";
						
						HtmlInputButton btnClear = new HtmlInputButton("button");
						tdField.Controls.Add(btnClear);
						btnClear.ID = sDATA_FIELD + "_btnClear";
						btnClear.Attributes.Add("class", "button");
						// 07/27/2010   Add the ability to submit after clear. 
						btnClear.Attributes.Add("onclick"  , "return ClearModuleType('" + sMODULE_TYPE + "', '" + hidID.ClientID + "', '" + txtNAME.ClientID + "', " + (arrDATA_FORMAT[0] == "1" ? "true" : "false") + ");");
						btnClear.Attributes.Add("title"    , L10n.Term(".LBL_CLEAR_BUTTON_TITLE"));
						btnClear.Value = L10n.Term(".LBL_CLEAR_BUTTON_LABEL");
						// 01/18/2010   Apply ACL Field Security. 
						btnClear.Visible  =   bLayoutMode || bIsReadable;
						btnClear.Disabled = !(bLayoutMode || bIsWriteable);
						
						// 11/11/2010   Always create the Required Field Validator so that we can Enable/Disable in a Rule. 
						if ( !bLayoutMode && /* bUI_REQUIRED && */ !Sql.IsEmptyString(sDATA_FIELD) )
						{
							RequiredFieldValidatorForHiddenInputs reqID = new RequiredFieldValidatorForHiddenInputs();
							reqID.ID                 = sDATA_FIELD + "_REQUIRED";
							reqID.ControlToValidate  = hidID.ID;
							reqID.ErrorMessage       = L10n.Term(".ERR_REQUIRED_FIELD");
							reqID.CssClass           = "required";
							reqID.EnableViewState    = false;
							// 01/16/2006   We don't enable required fields until we attempt to save. 
							// This is to allow unrelated form actions; the Cancel button is a good example. 
							reqID.EnableClientScript = false;
							reqID.Enabled            = false;
							// 02/21/2008   Add a little padding. 
							reqID.Style.Add("padding-left", "4px");
							tdField.Controls.Add(reqID);
						}
						// 11/23/2009   Allow AJAX AutoComplete to be turned off. 
						// 01/18/2010   AutoComplete only applies if the field is Writeable. 
						if ( bAjaxAutoComplete && !bLayoutMode && mgrAjax != null && !Sql.IsEmptyString(sMODULE_TYPE) && bIsWriteable )
						{
							string sTABLE_NAME    = Sql.ToString(Application["Modules." + sMODULE_TYPE + ".TableName"   ]);
							string sRELATIVE_PATH = Sql.ToString(Application["Modules." + sMODULE_TYPE + ".RelativePath"]);
							
							// 09/03/2009   File IO is expensive, so cache the results of the Exists test. 
							// 11/19/2009   Simplify the exists test. 
							// 03/03/2010   AutoComplete will not work if the DISPLAY_FIELD is not provided. 
							// 09/08/2010   sRELATIVE_PATH must be valid. 
							// 08/25/2013   File IO is slow, so cache existance test. 
							if ( !Sql.IsEmptyString(sDISPLAY_FIELD) && !Sql.IsEmptyString(sRELATIVE_PATH) && Utils.CachedFileExists(HttpContext.Current, sRELATIVE_PATH + "AutoComplete.asmx") )
							{
								// 09/03/2009   If the AutoComplete file exists, then we can safely diable the ReadOnly flag. 
								txtNAME.ReadOnly = false;
								txtNAME.Attributes.Add("onblur", sTABLE_NAME + "_" + txtNAME.ID + "_Changed(this);");
								// 09/03/2009   Add a PREV_ field so that we can detect a text change. 
								HtmlInputHidden hidPREVIOUS = new HtmlInputHidden();
								tdField.Controls.Add(hidPREVIOUS);
								hidPREVIOUS.ID = "PREV_" + sDISPLAY_FIELD;
								try
								{
									if ( !bLayoutMode )
									{
										if ( !Sql.IsEmptyString(sDISPLAY_FIELD) && rdr != null )
											hidPREVIOUS.Value = Sql.ToString(rdr[sDISPLAY_FIELD]);
										else if ( sEDIT_NAME.IndexOf(".Search") < 0 && sDATA_FIELD == "TEAM_ID" && rdr == null && !bIsPostBack )
											hidPREVIOUS.Value = Security.TEAM_NAME;
										else if ( sEDIT_NAME.IndexOf(".Search") < 0 && sDATA_FIELD == "ASSIGNED_USER_ID" && rdr == null && !bIsPostBack )
										{
											// 01/29/2011   If Full Names have been enabled, then prepopulate with the full name. 
											if ( sDISPLAY_FIELD == "ASSIGNED_TO_NAME" )
												hidPREVIOUS.Value = Security.FULL_NAME;
											else
												hidPREVIOUS.Value = Security.USER_NAME;
										}
									}
								}
								catch(Exception ex)
								{
									SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
								}
								
								AjaxControlToolkit.AutoCompleteExtender auto = new AjaxControlToolkit.AutoCompleteExtender();
								tdField.Controls.Add(auto);
								auto.ID                   = "auto" + txtNAME.ID;
								auto.TargetControlID      = txtNAME.ID;
								auto.ServiceMethod        = sTABLE_NAME + "_" + txtNAME.ID + "_" + "List";
								auto.ServicePath          = sRELATIVE_PATH + "AutoComplete.asmx";
								auto.MinimumPrefixLength  = 2;
								auto.CompletionInterval   = 250;
								auto.EnableCaching        = true;
								// 12/09/2010   Provide a way to customize the AutoComplete.CompletionSetCount. 
								auto.CompletionSetCount   = Crm.Config.CompletionSetCount();
								// 07/27/2010   We need to use the ContextKey feature of AutoComplete to pass the Account Name to the Contact function. 
								// 07/27/2010   JavaScript seems to have a problem with function overloading. 
								// Instead of trying to use function overloading, use a DataFormat flag to check the UseContextKey AutoComplete flag. 
								if ( arrDATA_FORMAT.Length > 1 && arrDATA_FORMAT[1] == "1" )
									auto.UseContextKey = true;
								
								ServiceReference svc = new ServiceReference(sRELATIVE_PATH + "AutoComplete.asmx");
								ScriptReference  scr = new ScriptReference (sRELATIVE_PATH + "AutoComplete.js"  );
								if ( !mgrAjax.Services.Contains(svc) )
									mgrAjax.Services.Add(svc);
								if ( !mgrAjax.Scripts.Contains(scr) )
									mgrAjax.Scripts.Add(scr);
								
								litNBSP = new Literal();
								tdField.Controls.Add(litNBSP);
								litNBSP.Text = "&nbsp;";
								// 09/03/2009   We need to use a unique ID for each ajax error, 
								// otherwise we will not place the error message in the correct location. 
								HtmlGenericControl spnAjaxErrors = new HtmlGenericControl("span");
								tdField.Controls.Add(spnAjaxErrors);
								// 09/03/2009   Don't include the table name in the AjaxErrors field so that 
								// it can be cleared from the ChangeModule() module popup script. 
								spnAjaxErrors.ID = txtNAME.ID + "_AjaxErrors";
								spnAjaxErrors.Attributes.Add("style", "color:Red");
								spnAjaxErrors.EnableViewState = false;
							}
						}
						// 10/20/2010   Automatically associate the TextBox with a Submit button. 
						// 10/20/2010   We are still having a problem with the Enter Key hijacking the Auto-Complete logic. The most practical solution is to block the Enter Key. 
						if ( !bLayoutMode && !Sql.IsEmptyString(sSubmitClientID) )
						{
							if ( mgrAjax != null )
							{
								ScriptManager.RegisterStartupScript(Page, typeof(System.String), txtNAME.ClientID + "_EnterKey", Utils.PreventEnterKeyPress(txtNAME.ClientID), false);
							}
							else
							{
								#pragma warning disable 618
								Page.ClientScript.RegisterStartupScript(typeof(System.String), txtNAME.ClientID + "_EnterKey", Utils.PreventEnterKeyPress(txtNAME.ClientID));
								#pragma warning restore 618
							}
						}
					}
				}
				// 09/02/2009   Add AJAX AutoCompletion
				else if ( String.Compare(sFIELD_TYPE, "ModuleAutoComplete", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						TextBox txtField = new TextBox();
						tdField.Controls.Add(txtField);
						txtField.ID       = sDATA_FIELD;
						txtField.TabIndex = nFORMAT_TAB_INDEX;
						// 01/18/2010   Apply ACL Field Security. 
						txtField.Visible  = bLayoutMode || bIsReadable;
						txtField.Enabled  = bLayoutMode || bIsWriteable;
						try
						{
							txtField.MaxLength = nFORMAT_MAX_LENGTH   ;
							// 06/20/2009   The NewRecord forms do not specify a size. 
							if ( nFORMAT_SIZE > 0 )
								txtField.Attributes.Add("size", nFORMAT_SIZE.ToString());
							txtField.TextMode  = TextBoxMode.SingleLine;
							// 08/31/2012   Apple and Android devices should support speech and handwriting. 
							// Speech does not work on text areas, only add to single line text boxes. 
							if ( Utils.SupportsSpeech && Sql.ToBoolean(Application["CONFIG.enable_speech"]) )
							{
								txtField.Attributes.Add("speech", "speech");
								txtField.Attributes.Add("x-webkit-speech", "x-webkit-speech");
							}
							if ( bLayoutMode )
							{
								txtField.Text    = sDATA_FIELD;
								txtField.Enabled = false         ;
							}
							else if ( !Sql.IsEmptyString(sDATA_FIELD) && rdr != null )
								txtField.Text = Sql.ToString(rdr[sDATA_FIELD]);
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
							txtField.Text = ex.Message;
						}
						// 11/23/2009   Allow AJAX AutoComplete to be turned off. 
						// 01/18/2010   AutoComplete only applies if the field is Writeable. 
						if ( bAjaxAutoComplete && !bLayoutMode && mgrAjax != null && !Sql.IsEmptyString(sMODULE_TYPE) && bIsWriteable )
						{
							string sTABLE_NAME    = Sql.ToString(Application["Modules." + sMODULE_TYPE + ".TableName"   ]);
							string sRELATIVE_PATH = Sql.ToString(Application["Modules." + sMODULE_TYPE + ".RelativePath"]);
							
							// 09/03/2009   File IO is expensive, so cache the results of the Exists test. 
							// 11/19/2009   Simplify the exists test. 
							// 09/08/2010   sRELATIVE_PATH must be valid. 
							// 08/25/2013   File IO is slow, so cache existance test. 
							if ( !Sql.IsEmptyString(sRELATIVE_PATH) && Utils.CachedFileExists(HttpContext.Current, sRELATIVE_PATH + "AutoComplete.asmx") )
							{
								AjaxControlToolkit.AutoCompleteExtender auto = new AjaxControlToolkit.AutoCompleteExtender();
								tdField.Controls.Add(auto);
								auto.ID                   = "auto" + txtField.ID;
								auto.TargetControlID      = txtField.ID;
								auto.ServiceMethod        = sTABLE_NAME + "_" + txtField.ID + "_" + "List";
								auto.ServicePath          = sRELATIVE_PATH + "AutoComplete.asmx";
								auto.MinimumPrefixLength  = 2;
								auto.CompletionInterval   = 250;
								auto.EnableCaching        = true;
								// 12/09/2010   Provide a way to customize the AutoComplete.CompletionSetCount. 
								auto.CompletionSetCount   = Crm.Config.CompletionSetCount();
								
								ServiceReference svc = new ServiceReference(sRELATIVE_PATH + "AutoComplete.asmx");
								ScriptReference  scr = new ScriptReference (sRELATIVE_PATH + "AutoComplete.js"  );
								if ( !mgrAjax.Services.Contains(svc) )
									mgrAjax.Services.Add(svc);
								if ( !mgrAjax.Scripts.Contains(scr) )
									mgrAjax.Scripts.Add(scr);
							}
							else
							{
								Application["Exists." + sRELATIVE_PATH + "AutoComplete.asmx"] = false;
							}
						}
						// 06/21/2009   Automatically associate the TextBox with a Submit button. 
						if ( !bLayoutMode && !Sql.IsEmptyString(sSubmitClientID) )
						{
							if ( mgrAjax != null )
							{
								// 06/21/2009   The name of the script block must be unique for each instance of this control. 
								// 06/21/2009   Use RegisterStartupScript instead of RegisterClientScriptBlock so that the script will run after the control has been created. 
								ScriptManager.RegisterStartupScript(Page, typeof(System.String), txtField.ClientID + "_EnterKey", Utils.RegisterEnterKeyPress(txtField.ClientID, sSubmitClientID), false);
							}
							else
							{
								#pragma warning disable 618
								Page.ClientScript.RegisterStartupScript(typeof(System.String), txtField.ClientID + "_EnterKey", Utils.RegisterEnterKeyPress(txtField.ClientID, sSubmitClientID));
								#pragma warning restore 618
							}
						}
					}
				}
				else if ( String.Compare(sFIELD_TYPE, "TextBox", true) == 0 || String.Compare(sFIELD_TYPE, "Password", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						TextBox txtField = new TextBox();
						tdField.Controls.Add(txtField);
						txtField.ID       = sDATA_FIELD;
						txtField.TabIndex = nFORMAT_TAB_INDEX;
						// 01/18/2010   Apply ACL Field Security. 
						txtField.Visible  = bLayoutMode || bIsReadable;
						txtField.Enabled  = bLayoutMode || bIsWriteable;
						try
						{
							if ( nFORMAT_ROWS > 0 && nFORMAT_COLUMNS > 0 )
							{
								txtField.Rows     = nFORMAT_ROWS   ;
								txtField.Columns  = nFORMAT_COLUMNS;
								txtField.TextMode = TextBoxMode.MultiLine;
								
								// 08/22/2012   Apple and Android devices should support speech and handwriting. 
								// Speech does not work on text areas, only add to single line text boxes. 
								// http://www.labnol.org/software/add-speech-recognition-to-website/19989/
								if ( Utils.SupportsSpeech && Sql.ToBoolean(Application["CONFIG.enable_speech"]) )
								{
									TextBox txtSpeech = new TextBox();
									tdField.Controls.Add(txtSpeech);
									txtSpeech.ID       = sDATA_FIELD + "_SPEECH";
									txtSpeech.TabIndex = nFORMAT_TAB_INDEX;
									txtSpeech.Visible  = bLayoutMode || bIsReadable;
									txtSpeech.Enabled  = bLayoutMode || bIsWriteable;
									txtSpeech.Attributes.Add("style", "width: 15px; height: 20px; border: 0px; background-color: transparent; vertical-align:top;");
									txtSpeech.Attributes.Add("speech", "speech");
									txtSpeech.Attributes.Add("x-webkit-speech", "x-webkit-speech");
									txtSpeech.Attributes.Add("onspeechchange"      , "SpeechTranscribe('" + txtSpeech.ClientID + "', '" + txtField.ClientID + "');");
									txtSpeech.Attributes.Add("onwebkitspeechchange", "SpeechTranscribe('" + txtSpeech.ClientID + "', '" + txtField.ClientID + "');");
								}
							}
							else
							{
								txtField.MaxLength = nFORMAT_MAX_LENGTH   ;
								// 06/20/2009   The NewRecord forms do not specify a size. 
								if ( nFORMAT_SIZE > 0 )
									txtField.Attributes.Add("size", nFORMAT_SIZE.ToString());
								txtField.TextMode  = TextBoxMode.SingleLine;
								// 08/22/2012   Apple and Android devices should support speech and handwriting. 
								// Speech does not work on text areas, only add to single line text boxes. 
								// 08/31/2012  Exclude speech from Password fields. 
								if ( String.Compare(sFIELD_TYPE, "TextBox", true) == 0 && Utils.SupportsSpeech && Sql.ToBoolean(Application["CONFIG.enable_speech"]) )
								{
									txtField.Attributes.Add("speech", "speech");
									txtField.Attributes.Add("x-webkit-speech", "x-webkit-speech");
								}
							}
							if ( bLayoutMode )
							{
								txtField.Text     = sDATA_FIELD;
								txtField.ReadOnly = true       ;
							}
							else if ( !Sql.IsEmptyString(sDATA_FIELD) && rdr != null )
							{
								// 11/22/2010   Convert data reader to data table for Rules Wizard. 
								// 11/22/2010   There is no way to get the DbType from a DataTable/DataRow, so just rely upon the detection of Decimal. 
								//int    nOrdinal  = rdr.GetOrdinal(sDATA_FIELD);
								string sTypeName = String.Empty;  // rdr.GetDataTypeName(nOrdinal);
								Type tDATA_FIELD = rdr[sDATA_FIELD].GetType();
								// 03/04/2006   Display currency in the proper format. 
								// Only SQL Server is likely to return the money type, so also include the decimal type. 
								if ( sTypeName == "money" || tDATA_FIELD == typeof(System.Decimal) )
								{
									if ( Sql.IsEmptyString(sDATA_FORMAT) )
										txtField.Text = Sql.ToDecimal(rdr[sDATA_FIELD]).ToString("#,##0.00");
									else
										txtField.Text = Sql.ToDecimal(rdr[sDATA_FIELD]).ToString(sDATA_FORMAT);
								}
								// 01/19/2010   Now that ProjectTask.ESTIMATED_EFFORT is a float, we need to format the value. 
								else if ( tDATA_FIELD == typeof(System.Double) )
								{
									if ( Sql.IsEmptyString(sDATA_FORMAT) )
										txtField.Text = Sql.ToDouble(rdr[sDATA_FIELD]).ToString("0.00");
									else
										txtField.Text = Sql.ToDouble(rdr[sDATA_FIELD]).ToString(sDATA_FORMAT);
								}
								else if ( tDATA_FIELD == typeof(System.Int32) )
								{
									if ( Sql.IsEmptyString(sDATA_FORMAT) )
										txtField.Text = Sql.ToInteger(rdr[sDATA_FIELD]).ToString("0");
									else
										txtField.Text = Sql.ToInteger(rdr[sDATA_FIELD]).ToString(sDATA_FORMAT);
								}
								else
									txtField.Text = Sql.ToString(rdr[sDATA_FIELD]);
							}
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
							txtField.Text = ex.Message;
						}
						if ( String.Compare(sFIELD_TYPE, "Password", true) == 0 )
							txtField.TextMode = TextBoxMode.Password;
						// 09/16/2012   Add onchange event to TextBox. 
						else if ( String.Compare(sFIELD_TYPE, "TextBox", true) == 0 && !bLayoutMode )
						{
							if ( !Sql.IsEmptyString(sONCLICK_SCRIPT) )
								txtField.Attributes.Add("onchange" , sONCLICK_SCRIPT);
						}
						// 06/21/2009   Automatically associate the TextBox with a Submit button. 
						if ( !bLayoutMode && !Sql.IsEmptyString(sSubmitClientID) )
						{
							if ( mgrAjax != null )
							{
								// 06/21/2009   The name of the script block must be unique for each instance of this control. 
								// 06/21/2009   Use RegisterStartupScript instead of RegisterClientScriptBlock so that the script will run after the control has been created. 
								ScriptManager.RegisterStartupScript(Page, typeof(System.String), txtField.ClientID + "_EnterKey", Utils.RegisterEnterKeyPress(txtField.ClientID, sSubmitClientID), false);
							}
							else
							{
								#pragma warning disable 618
								Page.ClientScript.RegisterStartupScript(typeof(System.String), txtField.ClientID + "_EnterKey", Utils.RegisterEnterKeyPress(txtField.ClientID, sSubmitClientID));
								#pragma warning restore 618
							}
						}
						// 11/11/2010   Always create the Required Field Validator so that we can Enable/Disable in a Rule. 
						if ( !bLayoutMode && /* bUI_REQUIRED && */ !Sql.IsEmptyString(sDATA_FIELD) )
						{
							RequiredFieldValidator reqNAME = new RequiredFieldValidator();
							reqNAME.ID                 = sDATA_FIELD + "_REQUIRED";
							reqNAME.ControlToValidate  = txtField.ID;
							reqNAME.ErrorMessage       = L10n.Term(".ERR_REQUIRED_FIELD");
							reqNAME.CssClass           = "required";
							reqNAME.EnableViewState    = false;
							// 01/16/2006   We don't enable required fields until we attempt to save. 
							// This is to allow unrelated form actions; the Cancel button is a good example. 
							reqNAME.EnableClientScript = false;
							reqNAME.Enabled            = false;
							reqNAME.Style.Add("padding-left", "4px");
							tdField.Controls.Add(reqNAME);
						}
						if ( !bLayoutMode && !Sql.IsEmptyString(sDATA_FIELD) )
						{
							// 01/18/2010   We only need to validate if the field is Writeable. 
							if ( sVALIDATION_TYPE == "RegularExpressionValidator" && !Sql.IsEmptyString(sREGULAR_EXPRESSION) && !Sql.IsEmptyString(sFIELD_VALIDATOR_MESSAGE) && bIsWriteable )
							{
								RegularExpressionValidator reqVALIDATOR = new RegularExpressionValidator();
								reqVALIDATOR.ID                   = sDATA_FIELD + "_VALIDATOR";
								reqVALIDATOR.ControlToValidate    = txtField.ID;
								reqVALIDATOR.ErrorMessage         = L10n.Term(sFIELD_VALIDATOR_MESSAGE);
								reqVALIDATOR.ValidationExpression = sREGULAR_EXPRESSION;
								reqVALIDATOR.CssClass             = "required";
								reqVALIDATOR.EnableViewState      = false;
								// 04/02/2008   We don't enable required fields until we attempt to save. 
								// This is to allow unrelated form actions; the Cancel button is a good example. 
								reqVALIDATOR.EnableClientScript   = false;
								reqVALIDATOR.Enabled              = false;
								reqVALIDATOR.Style.Add("padding-left", "4px");
								tdField.Controls.Add(reqVALIDATOR);
							}
						}
					}
				}
				// 04/02/2009   Add support for FCKEditor to the EditView. 
				else if ( String.Compare(sFIELD_TYPE, "HtmlEditor", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						// 09/18/2011   Upgrade to CKEditor 3.6.2. 
						CKEditorControl txtField = new CKEditorControl();
						tdField.Controls.Add(txtField);
						txtField.ID         = sDATA_FIELD;
						txtField.Toolbar    = "Taoqi";
						// 09/18/2011   Set the language for CKEditor. 
						txtField.Language   = L10n.NAME;
						txtField.BasePath   = "~/ckeditor/";
						// 04/26/2012   Add file uploader. 
						txtField.FilebrowserUploadUrl    = txtField.ResolveUrl("~/ckeditor/upload.aspx");
						txtField.FilebrowserBrowseUrl    = txtField.ResolveUrl("~/Images/Popup.aspx");
						//txtField.FilebrowserWindowWidth  = "640";
						//txtField.FilebrowserWindowHeight = "480";
						// 01/18/2010   Apply ACL Field Security. 
						txtField.Visible  = bLayoutMode || bIsReadable;
						try
						{
							if ( nFORMAT_ROWS > 0 && nFORMAT_COLUMNS > 0 )
							{
								txtField.Height = nFORMAT_ROWS   ;
								txtField.Width  = nFORMAT_COLUMNS;
							}
							if ( bLayoutMode )
							{
								txtField.Text     = sDATA_FIELD;
							}
							else if ( !Sql.IsEmptyString(sDATA_FIELD) && rdr != null )
							{
								txtField.Text = Sql.ToString(rdr[sDATA_FIELD]);
								// 01/18/2010   FCKEditor does not have an Enable field, so just hide and replace with a Literal control. 
								if ( bIsReadable && !bIsWriteable )
								{
									txtField.Visible = false;
									Literal litField = new Literal();
									litField.ID = sDATA_FIELD + "_ReadOnly";
									tdField.Controls.Add(litField);
									litField.Text = Sql.ToString(rdr[sDATA_FIELD]);
								}
							}
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
							txtField.Text = ex.Message;
						}
						// 04/02/2009   The standard RequiredFieldValidator will not work on the FCKeditor. 
						/*
						if ( !bLayoutMode && bUI_REQUIRED && !Sql.IsEmptyString(sDATA_FIELD) )
						{
							RequiredFieldValidator reqNAME = new RequiredFieldValidator();
							reqNAME.ID                 = sDATA_FIELD + "_REQUIRED";
							reqNAME.ControlToValidate  = txtField.ID;
							reqNAME.ErrorMessage       = L10n.Term(".ERR_REQUIRED_FIELD");
							reqNAME.CssClass           = "required";
							reqNAME.EnableViewState    = false;
							// 01/16/2006   We don't enable required fields until we attempt to save. 
							// This is to allow unrelated form actions; the Cancel button is a good example. 
							reqNAME.EnableClientScript = false;
							reqNAME.Enabled            = false;
							reqNAME.Style.Add("padding-left", "4px");
							tdField.Controls.Add(reqNAME);
						}
						*/
					}
				}
				else if ( String.Compare(sFIELD_TYPE, "DatePicker", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						// 12/03/2005   UserControls must be loaded. 
						DatePicker ctlDate = tbl.Page.LoadControl("~/_controls/DatePicker.ascx") as DatePicker;
						tdField.Controls.Add(ctlDate);
						ctlDate.ID = sDATA_FIELD;
						// 05/06/2010   Use a special Page flag to override the default IsPostBack behavior. 
						ctlDate.NotPostBack = bNotPostBack;
						// 05/10/2006   Set the tab index. 
						ctlDate.TabIndex = nFORMAT_TAB_INDEX;
						// 01/18/2010   Apply ACL Field Security. 
						ctlDate.Visible  = bLayoutMode || bIsReadable;
						ctlDate.Enabled  = bLayoutMode || bIsWriteable;
						try
						{
							if ( rdr != null )
								ctlDate.Value = T10n.FromServerTime(rdr[sDATA_FIELD]);
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
						}
						// 01/16/2006   We validate elsewhere. 
						/*
						if ( !bLayoutMode && bUI_REQUIRED && !Sql.IsEmptyString(sDATA_FIELD) )
						{
							ctlDate.Required = true;
						}
						*/
						if ( bLayoutMode )
						{
							Literal litField = new Literal();
							litField.Text = sDATA_FIELD;
							tdField.Controls.Add(litField);
						}
					}
				}
				else if ( String.Compare(sFIELD_TYPE, "DateRange", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						// 12/17/2007   Use table to align before and after labels. 
						Table tblDateRange = new Table();
						tdField.Controls.Add(tblDateRange);
						TableRow trAfter = new TableRow();
						TableRow trBefore = new TableRow();
						tblDateRange.Rows.Add(trAfter);
						tblDateRange.Rows.Add(trBefore);
						TableCell tdAfterLabel  = new TableCell();
						TableCell tdAfterData   = new TableCell();
						TableCell tdBeforeLabel = new TableCell();
						TableCell tdBeforeData  = new TableCell();
						trAfter .Cells.Add(tdAfterLabel );
						trAfter .Cells.Add(tdAfterData  );
						trBefore.Cells.Add(tdBeforeLabel);
						trBefore.Cells.Add(tdBeforeData );

						// 12/03/2005   UserControls must be loaded. 
						DatePicker ctlDateStart = tbl.Page.LoadControl("~/_controls/DatePicker.ascx") as DatePicker;
						DatePicker ctlDateEnd   = tbl.Page.LoadControl("~/_controls/DatePicker.ascx") as DatePicker;
						Literal litAfterLabel  = new Literal();
						Literal litBeforeLabel = new Literal();
						litAfterLabel .Text = L10n.Term("SavedSearch.LBL_SEARCH_AFTER" );
						litBeforeLabel.Text = L10n.Term("SavedSearch.LBL_SEARCH_BEFORE");
						//tdField.Controls.Add(litAfterLabel );
						//tdField.Controls.Add(ctlDateStart  );
						//tdField.Controls.Add(litBeforeLabel);
						//tdField.Controls.Add(ctlDateEnd    );
						tdAfterLabel .Controls.Add(litAfterLabel );
						tdAfterData  .Controls.Add(ctlDateStart  );
						tdBeforeLabel.Controls.Add(litBeforeLabel);
						tdBeforeData .Controls.Add(ctlDateEnd    );

						ctlDateStart.ID = sDATA_FIELD + "_AFTER";
						ctlDateEnd  .ID = sDATA_FIELD + "_BEFORE";
						// 05/06/2010   Use a special Page flag to override the default IsPostBack behavior. 
						ctlDateStart.NotPostBack = bNotPostBack;
						ctlDateEnd  .NotPostBack = bNotPostBack;
						// 05/10/2006   Set the tab index. 
						ctlDateStart.TabIndex = nFORMAT_TAB_INDEX;
						ctlDateEnd  .TabIndex = nFORMAT_TAB_INDEX;

						// 01/18/2010   Apply ACL Field Security. 
						tblDateRange.Visible  = bLayoutMode || bIsReadable;
						ctlDateStart.Visible  = bLayoutMode || bIsReadable;
						ctlDateStart.Enabled  = bLayoutMode || bIsWriteable;
						// 01/18/2010   Apply ACL Field Security. 
						ctlDateEnd  .Visible  = bLayoutMode || bIsReadable;
						ctlDateEnd  .Enabled  = bLayoutMode || bIsWriteable;
						// 06/21/2009   Move SearchView EnterKey registration from SearchView.asx to here. 
						// 01/18/2010   Don't register the EnterKey unless the date is Writeable. 
						if ( !bLayoutMode && !Sql.IsEmptyString(sSubmitClientID) && bIsWriteable )
						{
							if ( mgrAjax != null )
							{
								// 06/21/2009   The name of the script block must be unique for each instance of this control. 
								// 06/21/2009   Use RegisterStartupScript instead of RegisterClientScriptBlock so that the script will run after the control has been created. 
								ScriptManager.RegisterStartupScript(Page, typeof(System.String), ctlDateStart.DateClientID + "_EnterKey", Utils.RegisterEnterKeyPress(ctlDateStart.DateClientID, sSubmitClientID), false);
								ScriptManager.RegisterStartupScript(Page, typeof(System.String), ctlDateEnd  .DateClientID + "_EnterKey", Utils.RegisterEnterKeyPress(ctlDateEnd  .DateClientID, sSubmitClientID), false);
							}
							else
							{
								#pragma warning disable 618
								Page.ClientScript.RegisterStartupScript(typeof(System.String), ctlDateStart.DateClientID + "_EnterKey", Utils.RegisterEnterKeyPress(ctlDateStart.DateClientID, sSubmitClientID));
								Page.ClientScript.RegisterStartupScript(typeof(System.String), ctlDateEnd  .DateClientID + "_EnterKey", Utils.RegisterEnterKeyPress(ctlDateEnd  .DateClientID, sSubmitClientID));
								#pragma warning restore 618
							}
						}
						try
						{
							if ( rdr != null )
							{
								ctlDateStart.Value = T10n.FromServerTime(rdr[sDATA_FIELD]);
								ctlDateEnd  .Value = T10n.FromServerTime(rdr[sDATA_FIELD]);
							}
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
						}
						// 01/16/2006   We validate elsewhere. 
						/*
						if ( !bLayoutMode && bUI_REQUIRED && !Sql.IsEmptyString(sDATA_FIELD) )
						{
							ctlDateStart.Required = true;
							ctlDateEnd  .Required = true;
						}
						*/
						if ( bLayoutMode )
						{
							Literal litField = new Literal();
							litField.Text = sDATA_FIELD;
							tdField.Controls.Add(litField);
						}
					}
				}
				else if ( String.Compare(sFIELD_TYPE, "DateTimePicker", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						// 12/03/2005   UserControls must be loaded. 
						DateTimePicker ctlDate = tbl.Page.LoadControl("~/_controls/DateTimePicker.ascx") as DateTimePicker;
						tdField.Controls.Add(ctlDate);
						ctlDate.ID = sDATA_FIELD;
						// 05/06/2010   Use a special Page flag to override the default IsPostBack behavior. 
						ctlDate.NotPostBack = bNotPostBack;
						// 05/10/2006   Set the tab index. 
						ctlDate.TabIndex = nFORMAT_TAB_INDEX;
						// 01/18/2010   Apply ACL Field Security. 
						ctlDate.Visible  = bLayoutMode || bIsReadable;
						ctlDate.Enabled  = bLayoutMode || bIsWriteable;
						try
						{
							if ( rdr != null )
								ctlDate.Value = T10n.FromServerTime(rdr[sDATA_FIELD]);
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
						}
						if ( bLayoutMode )
						{
							Literal litField = new Literal();
							litField.Text = sDATA_FIELD;
							tdField.Controls.Add(litField);
						}
					}
				}
				else if ( String.Compare(sFIELD_TYPE, "DateTimeEdit", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						// 12/03/2005   UserControls must be loaded. 
						DateTimeEdit ctlDate = tbl.Page.LoadControl("~/_controls/DateTimeEdit.ascx") as DateTimeEdit;
						tdField.Controls.Add(ctlDate);
						ctlDate.ID = sDATA_FIELD;
						// 05/06/2010   Use a special Page flag to override the default IsPostBack behavior. 
						ctlDate.NotPostBack = bNotPostBack;
						// 05/10/2006   Set the tab index. 
						ctlDate.TabIndex = nFORMAT_TAB_INDEX;
						// 01/18/2010   Apply ACL Field Security. 
						ctlDate.Visible  = bLayoutMode || bIsReadable;
						ctlDate.Enabled  = bLayoutMode || bIsWriteable;
						try
						{
							if ( rdr != null )
								ctlDate.Value = T10n.FromServerTime(rdr[sDATA_FIELD]);
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
						}
						if ( !bLayoutMode && bUI_REQUIRED )
						{
							ctlDate.EnableNone = false;
						}
						if ( bLayoutMode )
						{
							Literal litField = new Literal();
							litField.Text = sDATA_FIELD;
							tdField.Controls.Add(litField);
						}
					}
				}
				// 06/20/2009   Add DateTimeNewRecord so that the NewRecord forms can use the Dynamic rendering. 
				else if ( String.Compare(sFIELD_TYPE, "DateTimeNewRecord", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						// 12/03/2005   UserControls must be loaded. 
						DateTimeEdit ctlDate = tbl.Page.LoadControl("~/_controls/DateTimeNewRecord.ascx") as DateTimeEdit;
						tdField.Controls.Add(ctlDate);
						ctlDate.ID = sDATA_FIELD;
						// 05/06/2010   Use a special Page flag to override the default IsPostBack behavior. 
						ctlDate.NotPostBack = bNotPostBack;
						// 05/10/2006   Set the tab index. 
						ctlDate.TabIndex = nFORMAT_TAB_INDEX;
						// 01/18/2010   Apply ACL Field Security. 
						ctlDate.Visible  = bLayoutMode || bIsReadable;
						ctlDate.Enabled  = bLayoutMode || bIsWriteable;
						try
						{
							if ( rdr != null )
								ctlDate.Value = T10n.FromServerTime(rdr[sDATA_FIELD]);
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
						}
						if ( !bLayoutMode && bUI_REQUIRED )
						{
							ctlDate.EnableNone = false;
						}
						if ( bLayoutMode )
						{
							Literal litField = new Literal();
							litField.Text = sDATA_FIELD;
							tdField.Controls.Add(litField);
						}
					}
				}
				else if ( String.Compare(sFIELD_TYPE, "File", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						HtmlInputHidden ctlHidden = null;
						if ( !bLayoutMode )
						{
							HtmlInputFile ctlField = new HtmlInputFile();
							tdField.Controls.Add(ctlField);
							// 04/17/2006   The image needs to reference the file control. 
							// 11/25/2010   Appending _File breaks the previous behavior of Notes, Bugs and Documents.
							// 11/25/2010   The file field is special in that it may not exist as a table column. 
							// 12/01/2010   rdr will not be available during postback, so we cannot use it do determine the field name. 
							// 12/01/2010   The only solution is to fix the naming convention for Notes, Bugs and Documents. 
							//if ( rdr != null && rdr.Table.Columns.Contains(sDATA_FIELD) )
							{
								ctlField.ID = sDATA_FIELD + "_File";
								ctlHidden = new HtmlInputHidden();
								tdField.Controls.Add(ctlHidden);
								ctlHidden.ID = sDATA_FIELD;
							}
							//else
							//{
							//	ctlField.ID = sDATA_FIELD;
							//}
							ctlField.MaxLength = nFORMAT_MAX_LENGTH;
							ctlField.Size      = nFORMAT_SIZE;
							ctlField.Attributes.Add("TabIndex", nFORMAT_TAB_INDEX.ToString());
							// 01/18/2010   Apply ACL Field Security. 
							ctlField.Visible  =   bLayoutMode || bIsReadable;
							ctlField.Disabled = !(bLayoutMode || bIsWriteable);

							Literal litBR = new Literal();
							litBR.Text = "<br />";
							tdField.Controls.Add(litBR);

							// 11/11/2010   Always create the Required Field Validator so that we can Enable/Disable in a Rule. 
							if ( !bLayoutMode /* && bUI_REQUIRED */ )
							{
								RequiredFieldValidator reqNAME = new RequiredFieldValidator();
								reqNAME.ID                 = sDATA_FIELD + "_REQUIRED";
								reqNAME.ControlToValidate  = ctlField.ID;
								reqNAME.ErrorMessage       = L10n.Term(".ERR_REQUIRED_FIELD");
								reqNAME.CssClass           = "required";
								reqNAME.EnableViewState    = false;
								// 01/16/2006   We don't enable required fields until we attempt to save. 
								// This is to allow unrelated form actions; the Cancel button is a good example. 
								reqNAME.EnableClientScript = false;
								reqNAME.Enabled            = false;
								reqNAME.Style.Add("padding-left", "4px");
								tdField.Controls.Add(reqNAME);
							}
						}
						
						// 11/23/2010   File needs to act like an Image. 
						HyperLink lnkField = new HyperLink();
						// 04/13/2006   Give the image a name so that it can be validated with SplendidTest. 
						lnkField.ID = "lnk" + sDATA_FIELD;
						// 01/18/2010   Apply ACL Field Security. 
						lnkField.Visible  = bLayoutMode || bIsReadable;
						try
						{
							if ( bLayoutMode )
							{
								Literal litField = new Literal();
								litField.Text = sDATA_FIELD;
								tdField.Controls.Add(litField);
							}
							else if ( rdr != null && rdr.Table.Columns.Contains(sDATA_FIELD) )
							{
								// 11/25/2010   The file field is special in that it may not exist as a table column. 
								if ( ctlHidden != null && !Sql.IsEmptyString(rdr[sDATA_FIELD]) )
								{
									ctlHidden.Value = Sql.ToString(rdr[sDATA_FIELD]);
									lnkField.NavigateUrl = "~/Images/Image.aspx?ID=" + ctlHidden.Value;
									lnkField.Text = Crm.Modules.ItemName(Application, "Images", ctlHidden.Value);
									// 04/13/2006   Only add the image if it exists. 
									tdField.Controls.Add(lnkField);
									
									// 04/17/2006   Provide a clear button. 
									Literal litClear = new Literal();
									litClear.Text = "&nbsp; <input type=\"button\" class=\"button\" onclick=\"document.getElementById('" + ctlHidden.ClientID + "').value='';document.getElementById('" + lnkField.ClientID + "').innerHTML='';" + "\"  value='" + "  " + L10n.Term(".LBL_CLEAR_BUTTON_LABEL" ) + "  " + "' title='" + L10n.Term(".LBL_CLEAR_BUTTON_TITLE" ) + "' />";
									tdField.Controls.Add(litClear);
								}
							}
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
							Literal litField = new Literal();
							litField.Text = ex.Message;
							tdField.Controls.Add(litField);
						}
					}
				}
				else if ( String.Compare(sFIELD_TYPE, "Image", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						HtmlInputHidden ctlHidden = new HtmlInputHidden();
						if ( !bLayoutMode )
						{
							tdField.Controls.Add(ctlHidden);
							ctlHidden.ID = sDATA_FIELD;

							HtmlInputFile ctlField = new HtmlInputFile();
							tdField.Controls.Add(ctlField);
							// 04/17/2006   The image needs to reference the file control. 
							ctlField.ID = sDATA_FIELD + "_File";
							ctlField.MaxLength = nFORMAT_MAX_LENGTH;
							ctlField.Size      = nFORMAT_SIZE;
							ctlField.Attributes.Add("TabIndex", nFORMAT_TAB_INDEX.ToString());
							// 01/18/2010   Apply ACL Field Security. 
							ctlField.Visible  =   bLayoutMode || bIsReadable;
							ctlField.Disabled = !(bLayoutMode || bIsWriteable);

							Literal litBR = new Literal();
							litBR.Text = "<br />";
							tdField.Controls.Add(litBR);

							// 11/25/2010   Add required field validator. 
							if ( !bLayoutMode /* && bUI_REQUIRED */ )
							{
								RequiredFieldValidator reqNAME = new RequiredFieldValidator();
								reqNAME.ID                 = sDATA_FIELD + "_REQUIRED";
								reqNAME.ControlToValidate  = ctlField.ID;
								reqNAME.ErrorMessage       = L10n.Term(".ERR_REQUIRED_FIELD");
								reqNAME.CssClass           = "required";
								reqNAME.EnableViewState    = false;
								// 01/16/2006   We don't enable required fields until we attempt to save. 
								// This is to allow unrelated form actions; the Cancel button is a good example. 
								reqNAME.EnableClientScript = false;
								reqNAME.Enabled            = false;
								reqNAME.Style.Add("padding-left", "4px");
								tdField.Controls.Add(reqNAME);
							}
						}
						
						Image imgField = new Image();
						// 04/13/2006   Give the image a name so that it can be validated with SplendidTest. 
						imgField.ID = "img" + sDATA_FIELD;
						// 01/18/2010   Apply ACL Field Security. 
						imgField.Visible  = bLayoutMode || bIsReadable;
						try
						{
							if ( bLayoutMode )
							{
								Literal litField = new Literal();
								litField.Text = sDATA_FIELD;
								tdField.Controls.Add(litField);
							}
							else if ( rdr != null )
							{
								if ( !Sql.IsEmptyString(rdr[sDATA_FIELD]) )
								{
									ctlHidden.Value = Sql.ToString(rdr[sDATA_FIELD]);
									imgField.ImageUrl = "~/Images/Image.aspx?ID=" + ctlHidden.Value;
									// 04/13/2006   Only add the image if it exists. 
									tdField.Controls.Add(imgField);
									
									// 04/17/2006   Provide a clear button. 
									Literal litClear = new Literal();
									litClear.Text = "&nbsp; <input type=\"button\" class=\"button\" onclick=\"document.getElementById('" + ctlHidden.ClientID + "').value='';document.getElementById('" + imgField.ClientID + "').src='';" + "\"  value='" + "  " + L10n.Term(".LBL_CLEAR_BUTTON_LABEL" ) + "  " + "' title='" + L10n.Term(".LBL_CLEAR_BUTTON_TITLE" ) + "' />";
									tdField.Controls.Add(litClear);
								}
							}
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
							Literal litField = new Literal();
							litField.Text = ex.Message;
							tdField.Controls.Add(litField);
						}
					}
				}
				else if ( String.Compare(sFIELD_TYPE, "AddressButtons", true) == 0 && (btnCopyRight == null) && (btnCopyLeft == null) )
				{
					trField.Cells.Remove(tdField);
					tdLabel.Width = "10%";
					tdLabel.RowSpan = nROWSPAN;
					tdLabel.VAlign  = "middle";
					tdLabel.Align   = "center";
					tdLabel.Attributes.Remove("class");
					tdLabel.Attributes.Add("class", "tabFormAddDel");
					// 05/08/2010   Define the copy buttons outside the loop so that we can replace the javascriptwith embedded code.  
					// This is so that the javascript will run properly in the SixToolbar UpdatePanel. 
					btnCopyRight = new HtmlInputButton("button");
					btnCopyLeft  = new HtmlInputButton("button");
					Literal         litSpacer    = new Literal();
					tdLabel.Controls.Add(btnCopyRight);
					tdLabel.Controls.Add(litSpacer   );
					tdLabel.Controls.Add(btnCopyLeft );
					btnCopyRight.Attributes.Add("title"  , L10n.Term("Accounts.NTC_COPY_BILLING_ADDRESS" ));
					//btnCopyRight.Attributes.Add("onclick", "return copyAddressRight()");
					btnCopyRight.Value = ">>";
					litSpacer.Text = "<br><br>";
					btnCopyLeft .Attributes.Add("title"  , L10n.Term("Accounts.NTC_COPY_SHIPPING_ADDRESS" ));
					//btnCopyLeft .Attributes.Add("onclick", "return copyAddressLeft()");
					btnCopyLeft .Value = "<<";
					nColIndex = 0;
				}
				else if ( String.Compare(sFIELD_TYPE, "Hidden", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						HtmlInputHidden hidID = new HtmlInputHidden();
						tdField.Controls.Add(hidID);
						hidID.ID = sDATA_FIELD;
						try
						{
							if ( bLayoutMode )
							{
								TextBox txtNAME = new TextBox();
								tdField.Controls.Add(txtNAME);
								txtNAME.ReadOnly = true;
								// 11/25/2006    Turn off viewstate so that we can fix the text on postback. 
								txtNAME.EnableViewState = false;
								txtNAME.Text    = sDATA_FIELD;
								txtNAME.Enabled = false         ;
							}
							else
							{
								// 02/28/2008   When the hidden field is the first in the row, we end up with a blank row. 
								// Just ignore for now as IE does not have a problem with the blank row. 
								nCOLSPAN = -1;
								trLabel.Cells.Remove(tdLabel);
								tdField.Attributes.Add("style", "display:none");
								if ( !Sql.IsEmptyString(sDATA_FIELD) && rdr != null )
									hidID.Value = Sql.ToString(rdr[sDATA_FIELD]);
								// 11/25/2006   The team name should always default to the current user's private team. 
								// Make sure not to overwrite the value if this is a postback. 
								// The hidden field does not require the same viewstate fix as the txtNAME field. 
								else if ( sDATA_FIELD == "TEAM_ID" && rdr == null && !bIsPostBack )
									hidID.Value = Security.TEAM_ID.ToString();
								// 01/15/2007   Assigned To field will always default to the current user. 
								else if ( sDATA_FIELD == "ASSIGNED_USER_ID" && rdr == null && !bIsPostBack )
									hidID.Value = Security.USER_ID.ToString();
							}
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
						}
					}
				}
				// 08/24/2009   Add support for dynamic teams. 
				else if ( String.Compare(sFIELD_TYPE, "TeamSelect", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						TeamSelect ctlTeamSelect = tbl.Page.LoadControl("~/_controls/TeamSelect.ascx") as TeamSelect;
						tdField.Controls.Add(ctlTeamSelect);
						ctlTeamSelect.ID = sDATA_FIELD;
						// 05/06/2010   Use a special Page flag to override the default IsPostBack behavior. 
						ctlTeamSelect.NotPostBack = bNotPostBack;
						//ctlTeamSelect.TabIndex = nFORMAT_TAB_INDEX;
						// 01/18/2010   Apply ACL Field Security. 
						ctlTeamSelect.Visible  = bLayoutMode || bIsReadable;
						ctlTeamSelect.Enabled  = bLayoutMode || bIsWriteable;
						try
						{
							Guid gTEAM_SET_ID = Guid.Empty;
							if ( rdr != null )
							{
								// 11/22/2010   Convert data reader to data table for Rules Wizard. 
								//vwSchema.RowFilter = "ColumnName = 'TEAM_SET_ID'";
								//if ( vwSchema.Count > 0 )
								if ( rdr.Table.Columns.Contains("TEAM_SET_ID") )
								{
									gTEAM_SET_ID = Sql.ToGuid(rdr["TEAM_SET_ID"]);
								}
							}
							// 08/31/2009  Don't provide defaults in a Search view or a Popup view. 
							bool bAllowDefaults = sEDIT_NAME.IndexOf(".Search") < 0 && sEDIT_NAME.IndexOf(".Popup") < 0;
							ctlTeamSelect.LoadLineItems(gTEAM_SET_ID, bAllowDefaults);
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
						}
						if ( bLayoutMode )
						{
							Literal litField = new Literal();
							litField.Text = sDATA_FIELD;
							tdField.Controls.Add(litField);
						}
					}
				}
				// 10/21/2009   Add support for dynamic teams. 
				else if ( String.Compare(sFIELD_TYPE, "KBTagSelect", true) == 0 )
				{
					if ( !Sql.IsEmptyString(sDATA_FIELD) )
					{
						KBTagSelect ctlKBTagSelect = tbl.Page.LoadControl("~/_controls/KBTagSelect.ascx") as KBTagSelect;
						tdField.Controls.Add(ctlKBTagSelect);
						ctlKBTagSelect.ID = sDATA_FIELD;
						// 05/06/2010   Use a special Page flag to override the default IsPostBack behavior. 
						ctlKBTagSelect.NotPostBack = bNotPostBack;
						//ctlKBTagSelect.TabIndex = nFORMAT_TAB_INDEX;
						// 01/18/2010   Apply ACL Field Security. 
						ctlKBTagSelect.Visible  = bLayoutMode || bIsReadable;
						ctlKBTagSelect.Enabled  = bLayoutMode || bIsWriteable;
						try
						{
							Guid gID = Guid.Empty;
							if ( rdr != null )
							{
								gID = Sql.ToGuid(rdr["ID"]);
							}
							ctlKBTagSelect.LoadLineItems(gID);
						}
						catch(Exception ex)
						{
							SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
						}
						if ( bLayoutMode )
						{
							Literal litField = new Literal();
							litField.Text = sDATA_FIELD;
							tdField.Controls.Add(litField);
						}
					}
				}
				else
				{
					Literal litField = new Literal();
					tdField.Controls.Add(litField);
					litField.Text = "Unknown field type " + sFIELD_TYPE;
					SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), "Unknown field type " + sFIELD_TYPE);
				}
				// 12/02/2007   Each view can now have its own number of data columns. 
				// This was needed so that search forms can have 4 data columns. The default is 2 columns. 
				if ( nCOLSPAN > 0 )
					nColIndex += nCOLSPAN;
				else if ( nCOLSPAN == 0 )
					nColIndex++;
				if ( nColIndex >= nDATA_COLUMNS )
					nColIndex = 0;
			}
			// 09/20/2012   We need a SCRIPT field that is form specific. 
			if ( dvFields.Count > 0 && !bLayoutMode )
			{
				try
				{
					string sEDIT_NAME   = Sql.ToString(dvFields[0]["EDIT_NAME"]);
					string sFORM_SCRIPT = Sql.ToString(dvFields[0]["SCRIPT"   ]);
					if ( !Sql.IsEmptyString(sFORM_SCRIPT) )
					{
						// 09/20/2012   The base ID is not the ID of the parent, but the ID of the TemplateControl. 
						sFORM_SCRIPT = sFORM_SCRIPT.Replace("SPLENDID_EDITVIEW_LAYOUT_ID", tbl.TemplateControl.ClientID);
						ScriptManager.RegisterStartupScript(tbl, typeof(System.String), sEDIT_NAME.Replace(".", "_") + "_SCRIPT", sFORM_SCRIPT, true);
					}
				}
				catch(Exception ex)
				{
					SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
				}
			}
			// 05/08/2010   Define the copy buttons outside the loop so that we can replace the javascript with embedded code.  
			// This is so that the javascript will run properly in the SixToolbar UpdatePanel. 
			if ( btnCopyRight != null && btnCopyLeft != null )
			{
				string[][] arrCopyFields = new string[14][];
				arrCopyFields[0] = new string[2] { "SHIPPING_ADDRESS_STREET"    , "BILLING_ADDRESS_STREET"    };
				arrCopyFields[1] = new string[2] { "SHIPPING_ADDRESS_CITY"      , "BILLING_ADDRESS_CITY"      };
				arrCopyFields[2] = new string[2] { "SHIPPING_ADDRESS_STATE"     , "BILLING_ADDRESS_STATE"     };
				arrCopyFields[3] = new string[2] { "SHIPPING_ADDRESS_POSTALCODE", "BILLING_ADDRESS_POSTALCODE"};
				arrCopyFields[4] = new string[2] { "SHIPPING_ADDRESS_COUNTRY"   , "BILLING_ADDRESS_COUNTRY"   };
				arrCopyFields[5] = new string[2] { "ALT_ADDRESS_STREET"         , "PRIMARY_ADDRESS_STREET"    };
				arrCopyFields[6] = new string[2] { "ALT_ADDRESS_CITY"           , "PRIMARY_ADDRESS_CITY"      };
				arrCopyFields[7] = new string[2] { "ALT_ADDRESS_STATE"          , "PRIMARY_ADDRESS_STATE"     };
				arrCopyFields[8] = new string[2] { "ALT_ADDRESS_POSTALCODE"     , "PRIMARY_ADDRESS_POSTALCODE"};
				arrCopyFields[9] = new string[2] { "ALT_ADDRESS_COUNTRY"        , "PRIMARY_ADDRESS_COUNTRY"   };
				// 08/21/2010   Also copy Account and Contact on Quotes, Orders and Invoices. 
				arrCopyFields[10] = new string[2] { "SHIPPING_ACCOUNT_NAME"      , "BILLING_ACCOUNT_NAME"      };
				arrCopyFields[11] = new string[2] { "SHIPPING_ACCOUNT_ID"        , "BILLING_ACCOUNT_ID"        };
				arrCopyFields[12] = new string[2] { "SHIPPING_CONTACT_NAME"      , "BILLING_CONTACT_NAME"      };
				arrCopyFields[13] = new string[2] { "SHIPPING_CONTACT_ID"        , "BILLING_CONTACT_ID"        };

				/*
				function copyAddressRight()
				{
					document.getElementById('<%= new DynamicControl(this, "SHIPPING_ADDRESS_STREET"    ).ClientID %>').value = document.getElementById('<%= new DynamicControl(this, "BILLING_ADDRESS_STREET"    ).ClientID %>').value;
					document.getElementById('<%= new DynamicControl(this, "SHIPPING_ADDRESS_CITY"      ).ClientID %>').value = document.getElementById('<%= new DynamicControl(this, "BILLING_ADDRESS_CITY"      ).ClientID %>').value;
					document.getElementById('<%= new DynamicControl(this, "SHIPPING_ADDRESS_STATE"     ).ClientID %>').value = document.getElementById('<%= new DynamicControl(this, "BILLING_ADDRESS_STATE"     ).ClientID %>').value;
					document.getElementById('<%= new DynamicControl(this, "SHIPPING_ADDRESS_POSTALCODE").ClientID %>').value = document.getElementById('<%= new DynamicControl(this, "BILLING_ADDRESS_POSTALCODE").ClientID %>').value;
					document.getElementById('<%= new DynamicControl(this, "SHIPPING_ADDRESS_COUNTRY"   ).ClientID %>').value = document.getElementById('<%= new DynamicControl(this, "BILLING_ADDRESS_COUNTRY"   ).ClientID %>').value;
					return true;
				}
				function copyAddressLeft()
				{
					document.getElementById('<%= new DynamicControl(this, "BILLING_ADDRESS_STREET"    ).ClientID %>').value = document.getElementById('<%= new DynamicControl(this, "SHIPPING_ADDRESS_STREET"    ).ClientID %>').value;
					document.getElementById('<%= new DynamicControl(this, "BILLING_ADDRESS_CITY"      ).ClientID %>').value = document.getElementById('<%= new DynamicControl(this, "SHIPPING_ADDRESS_CITY"      ).ClientID %>').value;
					document.getElementById('<%= new DynamicControl(this, "BILLING_ADDRESS_STATE"     ).ClientID %>').value = document.getElementById('<%= new DynamicControl(this, "SHIPPING_ADDRESS_STATE"     ).ClientID %>').value;
					document.getElementById('<%= new DynamicControl(this, "BILLING_ADDRESS_POSTALCODE").ClientID %>').value = document.getElementById('<%= new DynamicControl(this, "SHIPPING_ADDRESS_POSTALCODE").ClientID %>').value;
					document.getElementById('<%= new DynamicControl(this, "BILLING_ADDRESS_COUNTRY"   ).ClientID %>').value = document.getElementById('<%= new DynamicControl(this, "SHIPPING_ADDRESS_COUNTRY"   ).ClientID %>').value;
					return true;
				}
				*/
				StringBuilder sbCopyRight = new StringBuilder();
				StringBuilder sbCopyLeft  = new StringBuilder();
				for ( int i = 0; i < arrCopyFields.Length; i++ )
				{
					Control ctl1 = tbl.FindControl(arrCopyFields[i][0]);
					Control ctl2 = tbl.FindControl(arrCopyFields[i][1]);
					if ( ctl1 != null && ctl2 != null )
					{
						// 02/01/2011   Cannot copy values from literal. 
						if ( !(ctl1 is Literal) && !(ctl2 is Literal) )
						{
							sbCopyRight.Append("document.getElementById('" + ctl1.ClientID + "').value = document.getElementById('" + ctl2.ClientID + "').value;");
							sbCopyLeft .Append("document.getElementById('" + ctl2.ClientID + "').value = document.getElementById('" + ctl1.ClientID + "').value;");
						}
					}
				}
				sbCopyRight.Append("return true;");
				sbCopyLeft .Append("return true;");

				btnCopyRight.Attributes.Add("onclick", sbCopyRight.ToString());
				btnCopyLeft .Attributes.Add("onclick", sbCopyLeft .ToString());
			}
		}