protected void Page_Load(object sender, EventArgs e)
        {
            List <ListMetadataField> fields = this.ListFields;

            // register JS variable
            this.RegisterFieldInfoAsJSVariable();

            try
            {
                if (!Page.IsPostBack)
                {
                    if (this.View == null)
                    {
                        throw new Exception("Cannot find view!");
                    }

                    // set View Title
                    this.ViewName = this.View.Name;

                    // show/hide buttons base on 'IsDefault' flag
                    btnRemove.Visible        = chIsDefault.Visible = !this.View.IsDefault;
                    lblIsDefaultView.Visible = this.View.IsDefault;

                    // show/hide blocks base on Calendartype
                    this.ShowHideBlocksBaseOnViewType(this.View.IsCalendarView());

                    // init View settings
                    if (this.View.IsCalendarView())
                    {
                        // Init Calendar Columns COntrols
                        this.InitCalendarColumns(this.View.ViewData, fields);
                        // init Dyn settins
                        this.DynamicColourCodingSettings = this.View.DynamicColourCodingSettings;
                        // init static settings
                        this.StaticColourCodingSettings = this.View.StaticColourCodingSettings;

                        // init default scope
                        foreach (ListItem li in radioDefaultScope.Items)
                        {
                            li.Selected = (li.Value.Equals(this.View.CalendarScope));
                        }

                        // init Tooltip fields coll
                        List <ViewMetadataPopupSetting> tooltipFiedls = this.View.ViewMetadataPopupSettings.ToList();
                        TooltipColumnsGrid.DataSource = fields.Select((fld, index) => new {
                            IsSelected  = tooltipFiedls.Any(f => f.ListMetadataFieldId == fld.Id) ? "1" : "0",
                            Position    = tooltipFiedls.Where(f => f.ListMetadataFieldId == fld.Id).Select(f => f.Position).FirstOrDefault(),
                            Id          = fld.Id,
                            DisplayName = fld.FieldName,
                        }).OrderByDescending(x => x.IsSelected).ThenBy(x => x.Position);
                        TooltipColumnsGrid.DataBind();
                    }
                    else
                    {
                        this.ItemLimit = this.View.ItemLimit;

                        List <ViewMetadataField> viewFiedls = this.View.ViewMetadataFields.ToList();
                        string[] additionalFields           = this.View.ExcludeFields == null ? new string[0] : this.View.ExcludeFields.Split(new string[] { ";#" }, StringSplitOptions.RemoveEmptyEntries);
                        this.InitSortBlock(viewFiedls, fields);

                        var ds = new List <ViewField>();
                        foreach (var fld in fields)
                        {
                            var viewFld = viewFiedls.FirstOrDefault(f => f.ListMetadataFieldId == fld.Id);
                            ds.Add(new ViewField {
                                IsSelected  = viewFld != null ? "1" : "0",
                                Position    = viewFld == null ? 0 : viewFld.Position,
                                Id          = fld.Id.ToString(),
                                DisplayName = fld.FieldName
                            });

                            if ((fld.DataSourceType == (int)LookupSourceType.Table) || (fld.DataSourceType == (int)LookupSourceType.Query))
                            {
                                fld.DataSourceField.Split('$').Skip(1).ToList().ForEach(additionalField =>
                                {
                                    ds.Add(new ViewField {
                                        IsSelected  = additionalFields.Contains(string.Format("{0}_{1}", fld.DataSource, additionalField)) ? "1" : "0",
                                        Position    = viewFld == null ? 0 : viewFld.Position,
                                        Id          = string.Format("{0}_{1}", fld.DataSource, additionalField),
                                        DisplayName = string.Format("{0}: {1}", fld.FieldName, additionalField)
                                    });
                                });
                            }
                        }

                        ViewColumnsGrid.DataSource = ds.OrderByDescending(x => x.IsSelected).ThenBy(x => x.Position).ThenBy(x => x.DisplayName);
                        ViewColumnsGrid.DataBind();
                    }

                    // init Filter block
                    ddlFilterColumn.DataSource = fields;
                    ddlFilterColumn.DataBind();
                    this.Filters = this.View.ViewMetadataWhereCriteries;
                }
            }
            catch (Exception ex)
            {
                errorHolder.Controls.Add(new Label()
                {
                    Text = ex.Message, ForeColor = System.Drawing.Color.Red
                });
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            List <ListMetadataField> fields = this.ListFields;

            // register JS variable
            this.RegisterFieldInfoAsJSVariable();

            if (!Page.IsPostBack)
            {
                // show/hide blocks base on Calendartype
                this.ShowHideBlocksBaseOnViewType(this.IsCalendarView);

                if (this.IsCalendarView)
                {
                    // Init Calendar Columns COntrols
                    ddlMonthViewTitle.DataSource = fields;
                    ddlMonthViewTitle.DataBind();
                    ddlWeekViewTitle.DataSource = fields;
                    ddlWeekViewTitle.DataBind();
                    ddlWeekViewSubHeading.DataSource = fields;
                    ddlWeekViewSubHeading.DataBind();
                    ddlDayViewTitle.DataSource = fields;
                    ddlDayViewTitle.DataBind();
                    ddlDayViewSubHeading.DataSource = fields;
                    ddlDayViewSubHeading.DataBind();

                    // init Tooltip columns
                    TooltipColumnsGrid.DataSource = fields.Select((fld, index) => new {
                        IsSelected  = "0", // by default all fields are NOT selected - means no tooltip
                        Id          = fld.Id,
                        DisplayName = fld.FieldName,
                    }).OrderByDescending(x => x.DisplayName);
                    TooltipColumnsGrid.DataBind();
                }
                else
                {
                    ddlSortColumn.DataSource = fields;
                    ddlSortColumn.DataBind();

                    // init Grid view columns
                    var ds = new List <ViewField>();
                    foreach (var fld in fields)
                    {
                        ds.Add(new ViewField {
                            IsSelected  = "1", // by default all fields are selected
                            Position    = 0,
                            Id          = fld.Id.ToString(),
                            DisplayName = fld.FieldName
                        });

                        if ((fld.DataSourceType == (int)LookupSourceType.Table) || (fld.DataSourceType == (int)LookupSourceType.Query))
                        {
                            fld.DataSourceField.Split('$').Skip(1).ToList().ForEach(additionalField =>
                            {
                                ds.Add(new ViewField {
                                    IsSelected  = "0", // by default all additional fields are NOT selected
                                    Position    = 0,
                                    Id          = string.Format("{0}_{1}", fld.DataSource, additionalField),
                                    DisplayName = string.Format("{0}: {1}", fld.FieldName, additionalField)
                                });
                            });
                        }
                    }

                    ViewColumnsGrid.DataSource = ds.OrderByDescending(x => x.IsSelected).ThenBy(x => x.DisplayName);
                    ViewColumnsGrid.DataBind();
                }

                // init Filter block
                ddlFilterColumn.DataSource = fields;
                ddlFilterColumn.DataBind();
            }
        }