protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            SPList            TasksList;
            List <SPListItem> objNodeCollectionForDisplay = new List <SPListItem>();
            SPList            objTaskList;
            string            objLookupColumn = string.Empty;
            string            Title = string.Empty; string objNodeTitle = string.Empty;
            SPQuery           objSPQuery;
            StringBuilder     Query = new StringBuilder();

            string[] valueArray = null;


            if (!Page.IsPostBack)
            {
                if ((SPContext.Current.FormContext.FormMode == SPControlMode.New) || (SPContext.Current.FormContext.FormMode == SPControlMode.Edit))
                {
                    Microsoft.SharePoint.SPFieldMultiColumnValue values = (Microsoft.SharePoint.SPFieldMultiColumnValue) this.ListItemFieldValue;
                    if (values != null)
                    {
                        valueArray = values.ToString().Split(new string[] { ";#" }, StringSplitOptions.RemoveEmptyEntries);
                    }
                    TasksList = SPContext.Current.Web.Lists[objTreeViewControlField.ListName];

                    SPField spField = SPContext.Current.Web.Lists[objTreeViewControlField.ListName].Fields[objTreeViewControlField.ParentLookup];
                    if (!string.IsNullOrEmpty(objTreeViewControlField.ListName))
                    {
                        objSPQuery = new SPQuery();

                        Query.Append(String.Format("<Where><IsNull><FieldRef Name='" + spField.InternalName + "' /></IsNull></Where>"));


                        objSPQuery.Query = Query.ToString();

                        objItems = TasksList.GetItems(objSPQuery);

                        if (objItems != null && objItems.Count > 0)
                        {
                            foreach (SPListItem objItem in objItems)
                            {
                                DisplayColumn = Convert.ToString(objItem[objTreeViewControlField.ValueColumn]);
                                Title         = Convert.ToString(objItem[GlobalConstants.LIST_COLUMN_TITLE]);
                                CreateTree(Title, valueArray, null, DisplayColumn);
                            }
                        }
                    }
                }
                else
                {
                    objLookupColumn = objTreeViewControlField.ParentLookup;


                    if (this.ListItemFieldValue != null)
                    {
                        objTaskList = SPContext.Current.Web.Lists[objTreeViewControlField.ListName];
                        if (objTaskList != null)
                        {
                            valueArray = this.ListItemFieldValue.ToString().Split(new string[] { ";#" }, StringSplitOptions.RemoveEmptyEntries);
                            if (this.ControlMode == SPControlMode.Display)
                            {
                                objNodeCollectionForDisplay = CreateNodeCollectionForDisplay(valueArray);
                            }
                            List <SPListItem> results = (from SPListItem item in objNodeCollectionForDisplay
                                                         where (new SPFieldLookupValue(Convert.ToString(item[objTreeViewControlField.ParentLookup])).LookupValue == null)
                                                         orderby item.ID
                                                         select item).ToList();

                            foreach (SPListItem objLstItem in results)
                            {
                                CreateTree(objLstItem[GlobalConstants.LIST_COLUMN_TITLE].ToString(), null, objNodeCollectionForDisplay, objLstItem[objTreeViewControlField.ValueColumn].ToString());
                            }
                            // objTreeView.RenderControl(output);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Represents the method that handles the System.Web.UI.Control.PreRender event
        /// of a Microsoft.SharePoint.WebControls.FieldMetadata object.
        /// </summary>
        /// <param name="e">An System.EventArgs that contains the event data.</param>
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            SPList            TasksList;
            List <SPListItem> objNodeCollectionForDisplay = new List <SPListItem>();
            SPList            objTaskList;
            string            objLookupColumn = string.Empty;
            string            Title = string.Empty; string objNodeTitle = string.Empty;
            SPQuery           objSPQuery;
            StringBuilder     Query = new StringBuilder();

            string[] valueArray = null;
            SPField  spField;

            if (!Page.IsPostBack)
            {
                try
                {
                    lblExptnMsg.Text = string.Empty;;
                    if ((SPContext.Current.FormContext.FormMode == SPControlMode.New) || (SPContext.Current.FormContext.FormMode == SPControlMode.Edit))
                    {
                        Microsoft.SharePoint.SPFieldMultiColumnValue objMultiColumnValues = (Microsoft.SharePoint.SPFieldMultiColumnValue) this.ListItemFieldValue;
                        if (objMultiColumnValues != null)
                        {
                            valueArray = objMultiColumnValues.ToString().Split(new string[] { GlobalConstants.VALUE_SEPARATOR }, StringSplitOptions.RemoveEmptyEntries);
                        }
                        TasksList = SPContext.Current.Web.Lists[objTreeViewControlField.ListName];

                        spField = SPContext.Current.Web.Lists[objTreeViewControlField.ListName].Fields[objTreeViewControlField.ParentLookup];
                        if (!string.IsNullOrEmpty(objTreeViewControlField.ListName))
                        {
                            objSPQuery = new SPQuery();
                            Query.Append(String.Format(GlobalConstants.DYNAMIC_CAML_QUERY, spField.InternalName));
                            objSPQuery.Query = Query.ToString();
                            objItems         = TasksList.GetItems(objSPQuery);
                            if (objItems != null && objItems.Count > 0)
                            {
                                foreach (SPListItem objItem in objItems)
                                {
                                    DisplayColumn = Convert.ToString(objItem[objTreeViewControlField.ValueColumn]);
                                    Title         = Convert.ToString(objItem[GlobalConstants.LIST_COLUMN_TITLE]);
                                    CreateTree(Title, valueArray, null, DisplayColumn, objItem[objTreeViewControlField.KeyColumn].ToString());
                                }
                            }
                        }
                    }
                    else
                    {
                        objLookupColumn = objTreeViewControlField.ParentLookup;
                        if (this.ListItemFieldValue != null)
                        {
                            objTaskList = SPContext.Current.Web.Lists[objTreeViewControlField.ListName];
                            if (objTaskList != null)
                            {
                                valueArray = this.ListItemFieldValue.ToString().Split(new string[] { GlobalConstants.VALUE_SEPARATOR }, StringSplitOptions.RemoveEmptyEntries);
                                if (this.ControlMode == SPControlMode.Display)
                                {
                                    objNodeCollectionForDisplay = CreateNodeCollectionForDisplay(valueArray);
                                }
                                List <SPListItem> results = (from SPListItem item in objNodeCollectionForDisplay
                                                             where (new SPFieldLookupValue(Convert.ToString(item[objTreeViewControlField.ParentLookup])).LookupValue == null)
                                                             orderby item.ID
                                                             select item).ToList();

                                foreach (SPListItem objLstItem in results)
                                {
                                    CreateTree(objLstItem[GlobalConstants.LIST_COLUMN_TITLE].ToString(), null, objNodeCollectionForDisplay, objLstItem[objTreeViewControlField.ValueColumn].ToString(), objLstItem[objTreeViewControlField.KeyColumn].ToString());
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (string.IsNullOrEmpty(Convert.ToString(ex.InnerException)))
                    {
                        lblExptnMsg.Text = ex.Message;
                    }
                    else
                    {
                        lblExptnMsg.Text = Convert.ToString(ex.InnerException);
                    }
                }
            }
        }