/// <summary>
        /// Настройка элементов управления для форм
        /// </summary>
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            if (Field == null)
            {
                return;
            }

            //чтение свойств поля
            _connString       = Field.GetCustomProperty("ConnectionString").ToString();
            _queryString      = Field.GetCustomProperty("QueryString").ToString();
            _pickerEntityMode = (bool)Field.GetCustomProperty("PickerEntity");

            SharedModule.CheckConnectionProperties(FieldName, _connString, _queryString);

            //В НАДЕЖДЕ НА СВЕТЛОЕ БУДУЩЕЕ
            //this.multiSelectMode = Field.GetCustomProperty("MultiSelect");

            MultiSelectMode = Field.TypeAsString == "CustomExternalLookupMulti";

            //создание и настройка контролов для режима отображения
            if (ControlMode == SPControlMode.Display)
            {
                _fieldValueLiteral = TemplateContainer.FindControl("FieldValueLiteral") as EncodedLiteral;

                if (_fieldValueLiteral == null)
                {
                    MissingControlException("FieldValueLiteral");
                }

                if (ItemFieldValue != null && ItemFieldValue.ToString() != "")
                {
                    _fieldValueLiteral.Text = MultiSelectMode ? SharedModule.BuildHtmlForDisplayMultiColumn(ItemFieldValue) : ItemFieldValue.ToString();
                }

                return;
            }

            //создание и настройка контролов для режимов создания и редактирования элемента
            _fieldPanel = TemplateContainer.FindControl("FieldPanel") as Panel;
            if (_fieldPanel == null)
            {
                MissingControlException("FieldPanel");
            }

            _messagesLiteral = TemplateContainer.FindControl("MessagesLiteral") as EncodedLiteral;
            if (_messagesLiteral == null)
            {
                MissingControlException("MessagesLiteral");
            }

            //в настроках включён выбор с помощью EntityPicker'a
            if (_pickerEntityMode)
            {
                _entityEditor = (CustomExternalLookupEditor)TemplateContainer.FindControl("EntityEditor");
                if (_entityEditor == null)
                {
                    MissingControlException("EntityEditor");
                }

                _entityEditor.Visible = true;

                if (MultiSelectMode)
                {
                    //множественный выбор
                    _entityEditor.MultiSelect     = true;
                    _entityEditor.Rows            = 8;
                    _entityEditor.MaximumEntities = 0;
                    _entityEditor.PlaceButtonsUnderEntityEditor = true;
                }
                else
                {
                    _entityEditor.MultiSelect     = false;
                    _entityEditor.Rows            = 2;
                    _entityEditor.MaximumEntities = 1;
                    _entityEditor.PlaceButtonsUnderEntityEditor = false;
                }
                _entityEditor.DialogWidth  = 800;
                _entityEditor.DialogHeight = 600;
                _entityEditor.ToolTip      = Field.Title;
            }
            //иначе - выбор из списков
            else
            {
                if (MultiSelectMode)
                {
                    _listBoxesPanel = TemplateContainer.FindControl("ListBoxesPanel") as Panel;
                    if (_listBoxesPanel == null)
                    {
                        MissingControlException("ListBoxesPanel");
                    }

                    _listBoxesPanel.Visible = true;

                    _leftListBox = TemplateContainer.FindControl("LeftListBox") as ListBox;
                    if (_leftListBox == null)
                    {
                        MissingControlException("LeftListBox");
                    }

                    _rightListBox = TemplateContainer.FindControl("RightListBox") as ListBox;
                    if (_rightListBox == null)
                    {
                        MissingControlException("RightListBox");
                    }

                    _rightListBoxValues = TemplateContainer.FindControl("RightListBoxValues") as HiddenField;
                    if (_rightListBoxValues == null)
                    {
                        MissingControlException("RightListBoxValues");
                    }

                    //настройка размеров листбоксов для множественного выбора
                    int height        = 125,
                        width         = 143;
                    object heightTemp = Field.GetCustomProperty("Height");
                    if (heightTemp != null)
                    {
                        height = Convert.ToInt32(heightTemp);
                    }
                    object widthTemp = Field.GetCustomProperty("Width");
                    if (widthTemp != null)
                    {
                        width = Convert.ToInt32(widthTemp);
                    }

                    _leftListBox.Width  = _rightListBox.Width = width;
                    _leftListBox.Height = _rightListBox.Height = height;

                    //настройка вертикального расположения
                    var vertical = (bool)Field.GetCustomProperty("Vertical");
                    if (vertical)
                    {
                        var CELGroup1 = TemplateContainer.FindControl("CELGroup1") as Panel;
                        if (CELGroup1 == null)
                        {
                            MissingControlException("CELGroup1");
                        }

                        var CELGroupButtons = TemplateContainer.FindControl("CELGroupButtons") as Panel;
                        if (CELGroupButtons == null)
                        {
                            MissingControlException("CELGroupButtons");
                        }

                        var CELGroup2 = TemplateContainer.FindControl("CELGroup2") as Panel;
                        if (CELGroup2 == null)
                        {
                            MissingControlException("CELGroup2");
                        }

                        CELGroup1.CssClass       = CELGroup2.Attributes["class"] = "CELGroupVertical";
                        CELGroupButtons.CssClass = "CELButtonsVertical";

                        var AddButton = TemplateContainer.FindControl("AddButton") as Button;
                        if (AddButton == null)
                        {
                            MissingControlException("AddButton");
                        }

                        var RemoveButton = TemplateContainer.FindControl("RemoveButton") as Button;
                        if (RemoveButton == null)
                        {
                            MissingControlException("RemoveButton");
                        }

                        AddButton.Text    = "∨ Добавить";
                        RemoveButton.Text = "∧ Удалить";
                    }
                }
                else
                {
                    _dropDownList = TemplateContainer.FindControl("DropDownList") as DropDownList;
                    if (_dropDownList == null)
                    {
                        MissingControlException("DropDownList");
                    }

                    _dropDownList.Visible = true;
                    _dropDownList.ToolTip = Field.Title;
                }
            }
        }
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            SPSite site = null;
             SPWeb web = null;
            bool disposeSPSite = false;

            try
            {
                if (SourceList != string.Empty && SourceList != string.Empty)
                 {
                     viewByQuery = new ListViewByQuery();

                     if (!string.IsNullOrEmpty(SiteUrl))
                     {
                         site = new SPSite(SiteUrl);
                         disposeSPSite = true;
                     }
                     else
                     {
                         site = SPContext.Current.Site;
                     }

                     web = site.OpenWeb();
                     SPList sourceList = web.Lists[SourceList];
                     viewByQuery.List = sourceList;
                     SPQuery query = null;

                     query = CheckIfViewExists(viewByQuery.List)
                         ? new SPQuery(viewByQuery.List.Views[ViewName])
                         : new SPQuery(viewByQuery.List.DefaultView);

                     viewByQuery.Query = query;
                     viewByQuery.DisableFilter = DisableFilter;
                     viewByQuery.DisableSort = DisableSort;
                     Controls.Add(viewByQuery);
                 }
                 else
                 {
                     encodedLiteral = new EncodedLiteral { Text = "This webpart is not configured." };
                     Controls.Add(encodedLiteral);
                 }
            }
            finally
            {
                if (disposeSPSite)
                {
                    if (site != null)
                    {
                        ((IDisposable)site).Dispose();
                    }

                    if (web != null)
                    {
                        ((IDisposable)web).Dispose();
                    }
                }
            }
        }
        /// <summary>
        /// Настройка элементов управления для форм
        /// </summary>
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            if (Field == null)
                return;

            //чтение свойств поля
            _connString = Field.GetCustomProperty("ConnectionString").ToString();
            _queryString = Field.GetCustomProperty("QueryString").ToString();
            _pickerEntityMode = (bool)Field.GetCustomProperty("PickerEntity");

            SharedModule.CheckConnectionProperties(FieldName, _connString, _queryString);

            //В НАДЕЖДЕ НА СВЕТЛОЕ БУДУЩЕЕ
            //this.multiSelectMode = Field.GetCustomProperty("MultiSelect");

            MultiSelectMode = Field.TypeAsString == "CustomExternalLookupMulti";

            //создание и настройка контролов для режима отображения
            if (ControlMode == SPControlMode.Display)
            {
                _fieldValueLiteral = TemplateContainer.FindControl("FieldValueLiteral") as EncodedLiteral;

                if (_fieldValueLiteral == null)
                    MissingControlException("FieldValueLiteral");

                if (ItemFieldValue != null && ItemFieldValue.ToString() != "")
                    _fieldValueLiteral.Text = MultiSelectMode ? SharedModule.BuildHtmlForDisplayMultiColumn(ItemFieldValue) : ItemFieldValue.ToString();

                return;
            }

            //создание и настройка контролов для режимов создания и редактирования элемента
            _fieldPanel = TemplateContainer.FindControl("FieldPanel") as Panel;
            if (_fieldPanel == null)
                MissingControlException("FieldPanel");

            _messagesLiteral = TemplateContainer.FindControl("MessagesLiteral") as EncodedLiteral;
            if (_messagesLiteral == null)
                MissingControlException("MessagesLiteral");

            //в настроках включён выбор с помощью EntityPicker'a
            if (_pickerEntityMode)
            {
                _entityEditor = (CustomExternalLookupEditor)TemplateContainer.FindControl("EntityEditor");
                if (_entityEditor == null)
                    MissingControlException("EntityEditor");

                _entityEditor.Visible = true;

                if (MultiSelectMode)
                {
                    //множественный выбор
                    _entityEditor.MultiSelect = true;
                    _entityEditor.Rows = 8;
                    _entityEditor.MaximumEntities = 0;
                    _entityEditor.PlaceButtonsUnderEntityEditor = true;
                }
                else
                {
                    _entityEditor.MultiSelect = false;
                    _entityEditor.Rows = 2;
                    _entityEditor.MaximumEntities = 1;
                    _entityEditor.PlaceButtonsUnderEntityEditor = false;
                }
                _entityEditor.DialogWidth = 800;
                _entityEditor.DialogHeight = 600;
                _entityEditor.ToolTip = Field.Title;

            }
            //иначе - выбор из списков
            else
            {
                if (MultiSelectMode)
                {
                    _listBoxesPanel = TemplateContainer.FindControl("ListBoxesPanel") as Panel;
                    if (_listBoxesPanel == null)
                        MissingControlException("ListBoxesPanel");

                    _listBoxesPanel.Visible = true;

                    _leftListBox = TemplateContainer.FindControl("LeftListBox") as ListBox;
                    if (_leftListBox == null)
                        MissingControlException("LeftListBox");

                    _rightListBox = TemplateContainer.FindControl("RightListBox") as ListBox;
                    if (_rightListBox == null)
                        MissingControlException("RightListBox");

                    _rightListBoxValues = TemplateContainer.FindControl("RightListBoxValues") as HiddenField;
                    if (_rightListBoxValues == null)
                        MissingControlException("RightListBoxValues");

                    //настройка размеров листбоксов для множественного выбора
                    int height = 125,
                        width  = 143;
                    object heightTemp = Field.GetCustomProperty("Height");
                    if (heightTemp != null)
                        height = Convert.ToInt32(heightTemp);
                    object widthTemp = Field.GetCustomProperty("Width");
                    if (widthTemp != null)
                        width = Convert.ToInt32(widthTemp);

                    _leftListBox.Width = _rightListBox.Width = width;
                    _leftListBox.Height = _rightListBox.Height = height;

                    //настройка вертикального расположения
                    var vertical = (bool)Field.GetCustomProperty("Vertical");
                    if (vertical)
                    {
                        var CELGroup1 = TemplateContainer.FindControl("CELGroup1") as Panel;
                        if (CELGroup1 == null)
                            MissingControlException("CELGroup1");

                        var CELGroupButtons = TemplateContainer.FindControl("CELGroupButtons") as Panel;
                        if (CELGroupButtons == null)
                            MissingControlException("CELGroupButtons");

                        var CELGroup2 = TemplateContainer.FindControl("CELGroup2") as Panel;
                        if (CELGroup2 == null)
                            MissingControlException("CELGroup2");

                        CELGroup1.CssClass = CELGroup2.Attributes["class"] ="CELGroupVertical";
                        CELGroupButtons.CssClass = "CELButtonsVertical";

                        var AddButton = TemplateContainer.FindControl("AddButton") as Button;
                        if (AddButton == null)
                            MissingControlException("AddButton");

                        var RemoveButton = TemplateContainer.FindControl("RemoveButton") as Button;
                        if (RemoveButton == null)
                            MissingControlException("RemoveButton");

                        AddButton.Text = "∨ Добавить";
                        RemoveButton.Text = "∧ Удалить";
                    }
                }
                else
                {
                    _dropDownList = TemplateContainer.FindControl("DropDownList") as DropDownList;
                    if (_dropDownList == null)
                        MissingControlException("DropDownList");

                    _dropDownList.Visible = true;
                    _dropDownList.ToolTip = Field.Title;
                }
            }
        }