Exemplo n.º 1
0
        /// <summary>
        /// Internals the bind header.
        /// </summary>
        private void internalBindHeader()
        {
            McMetaViewPreference mvPref = GetMetaViewPreference();
            int counter       = 0;
            int notMetaFields = 0;

            for (int i = 0; i < this.CustomColumns.Count; i++)
            {
                MainGrid.Columns[i].HeaderText        = CHelper.GetResFileString(this.CustomColumns[i].Title);
                MainGrid.Columns[i].ItemStyle.Width   = this.CustomColumns[i].Width;
                MainGrid.Columns[i].HeaderStyle.Width = this.CustomColumns[i].Width;
                notMetaFields++;
            }

            counter += this.CustomColumns.Count;

            foreach (MetaField field in this.VisibleMetaFields)
            {
                int _width = GetMetaViewPreference().GetMetaFieldWidth(counter - notMetaFields, 100);
                if (_width == 0)
                {
                    _width = 100;
                }
                MainGrid.Columns[counter].ItemStyle.Width   = _width;
                MainGrid.Columns[counter].HeaderStyle.Width = _width;

                //add sorting only for metaFileds that supports sorting at MetaData level
                if (MetaDataWrapper.IsSortable(field))
                {
                    MainGrid.Columns[counter].SortExpression = field.Name;
                }

                DataControlField controlField = MainGrid.Columns[counter];
                controlField.HeaderText = CHelper.GetResFileString(field.FriendlyName);

                // Raising event
                ChangingMetaGridColumnHeaderEventArgs e = new ChangingMetaGridColumnHeaderEventArgs(controlField, field);
                OnChangingMetaGridColumnHeader(e);

                #region Sorting header text (arrows up/down)
                if (mvPref.Sorting != null && mvPref.Sorting.Count > 0 && mvPref.Sorting[0].Source == field.Name)
                {
                    if (mvPref.Sorting[0].Type == SortingElementType.Asc)
                    {
                        MainGrid.Columns[counter].HeaderText += String.Format("&nbsp;<img alt='' border='0' src='{0}' />", this.ResolveUrl("~/images/IbnFramework/sort_asc.gif"));
                    }
                    else
                    {
                        MainGrid.Columns[counter].HeaderText += String.Format("&nbsp;<img alt='' border='0' src='{0}' />", this.ResolveUrl("~/images/IbnFramework/sort_desc.gif"));
                    }
                }
                #endregion

                counter++;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles the Sorting event of the MainGrid control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewSortEventArgs"/> instance containing the event data.</param>
        void MainGrid_Sorting(object sender, GridViewSortEventArgs e)
        {
            #region Check for field being meta field
            bool _flag = false;
            foreach (MetaField field in CurrentView.AvailableFields)
            {
                if (field.Name == e.SortExpression)
                {
                    _flag = true;
                    break;
                }
            }
            if (!_flag)
            {
                return;
            }
            #endregion

            McMetaViewPreference mvPref = GetMetaViewPreference();
            //fix bug when user try to sort column which doesn't support sorting at MetaData level
            if (!MetaDataWrapper.IsSortable(e.SortExpression, mvPref))
            {
                return;
            }

            //fix issue with ajaxcontroltoolkit 3.5
            Thread.Sleep(750);

            if (mvPref.Sorting == null || mvPref.Sorting.Count == 0)
            {
                SortingElement new_sort = new SortingElement();
                mvPref.Sorting.Add(new_sort);
            }

            SortingElement sort = mvPref.Sorting[0];
            if (sort.Source.Equals(e.SortExpression))
            {
                if (sort.Type == SortingElementType.Asc)
                {
                    sort.Type = SortingElementType.Desc;
                }
                else
                {
                    sort.Type = SortingElementType.Asc;
                }
            }
            else
            {
                sort.Source = e.SortExpression;
                sort.Type   = SortingElementType.Asc;
            }
        }