protected void lnkSort_Click(object sender, EventArgs e)
        {
            try
            {
                LinkButton lnk = (LinkButton)sender;
                if (lnk != null)
                {
                    if (shortway % 2 == 0)
                    {
                        ViewState["lastsorton"] = Convert.ToString(lnk.ID) + " ASC";
                    }
                    else
                    {
                        ViewState["lastsorton"] = Convert.ToString(lnk.ID) + " DESC";
                    }

                    BindGrid();

                    #region Sorting
                    try
                    {
                        System.Web.UI.WebControls.DataControlFieldHeaderCell thSort = (System.Web.UI.WebControls.DataControlFieldHeaderCell)lnk.Parent;
                        if (thSort != null)
                        {
                            try
                            {
                                int iCount = ((System.Web.UI.WebControls.TableRow)(((GridViewRow)thSort.Parent))).Cells.Count;
                                for (int i = 0; i < iCount; i++)
                                {
                                    System.Web.UI.WebControls.DataControlFieldHeaderCell thSort_Row = (System.Web.UI.WebControls.DataControlFieldHeaderCell)((System.Web.UI.WebControls.TableRow)(((GridViewRow)thSort.Parent))).Cells[i];
                                    (((System.Web.UI.WebControls.DataControlFieldCell)(thSort_Row)).ContainingField).HeaderStyle.CssClass = string.Empty;
                                }
                            }
                            catch { }

                            if (shortway % 2 == 0)
                            {
                                (((System.Web.UI.WebControls.DataControlFieldCell)(thSort)).ContainingField).HeaderStyle.CssClass = "sorting_asc";
                            }
                            else
                            {
                                (((System.Web.UI.WebControls.DataControlFieldCell)(thSort)).ContainingField).HeaderStyle.CssClass = "sorting_desc";
                            }
                        }
                    }
                    catch { }
                    #endregion

                    shortway++;
                }
            }
            catch (Exception ex)
            {
                Messagesection.Visible = true;
                Message.Text           = ex.Message;
                LogManager.Log(ex);
            }
        }
예제 #2
0
		protected virtual void InitializeRow (GridViewRow row, DataControlField[] fields)
		{
			DataControlCellType ctype;
			bool accessibleHeader = false;

			switch (row.RowType) {
			case DataControlRowType.Header:
				ctype = DataControlCellType.Header; 
				accessibleHeader = UseAccessibleHeader;
				break;
			case DataControlRowType.Footer:
				ctype = DataControlCellType.Footer;
				break;
			default:
				ctype = DataControlCellType.DataCell;
				break;
			}
			
			for (int n=0; n<fields.Length; n++) {
				DataControlField field = fields [n];
				
				DataControlFieldCell cell;
				if (((field is BoundField) && ((BoundField)field).DataField == RowHeaderColumn) || accessibleHeader)
					cell = new DataControlFieldHeaderCell (field, accessibleHeader ? TableHeaderScope.Column : TableHeaderScope.Row);
				else
					cell = new DataControlFieldCell (field);
				row.Cells.Add (cell);
				field.InitializeCell (cell, ctype, row.RowState, row.RowIndex);
			}
		}
예제 #3
0
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        protected virtual void InitializeRow(GridViewRow row, DataControlField[] fields) {
            DataControlRowType rowType = row.RowType;
            DataControlRowState rowState = row.RowState;
            int rowIndex = row.RowIndex;
            bool useAccessibleHeader = false;

            if (rowType == DataControlRowType.EmptyDataRow) {
                InitializeTemplateRow(row, fields.Length);
            }
            else {
                TableCellCollection cells = row.Cells;
                string rowHeaderColumn = RowHeaderColumn;

                if (rowType == DataControlRowType.Header) {
                    useAccessibleHeader = UseAccessibleHeader;
                }

                for (int i = 0; i < fields.Length; i++) {
                    DataControlFieldCell cell;

                    if ((rowType == DataControlRowType.Header) && useAccessibleHeader) {
                        cell = new DataControlFieldHeaderCell(fields[i]);
                        ((DataControlFieldHeaderCell)cell).Scope = TableHeaderScope.Column;
                        ((DataControlFieldHeaderCell)cell).AbbreviatedText = fields[i].AccessibleHeaderText;
                    }
                    else {
                        BoundField boundField = fields[i] as BoundField;
                        if (rowHeaderColumn.Length > 0 && boundField != null && boundField.DataField == rowHeaderColumn) {
                            cell = new DataControlFieldHeaderCell(fields[i]);
                            ((DataControlFieldHeaderCell)cell).Scope = TableHeaderScope.Row;
                        }
                        else {
                            cell = new DataControlFieldCell(fields[i]);
                        }
                    }

                    DataControlCellType cellType;
                    switch (rowType) {
                        case DataControlRowType.Header:
                            cellType = DataControlCellType.Header;
                            break;
                        case DataControlRowType.Footer:
                            cellType = DataControlCellType.Footer;
                            break;
                        default:
                            cellType = DataControlCellType.DataCell;
                            break;
                    }
                    fields[i].InitializeCell(cell, cellType, rowState, rowIndex);
                    cells.Add(cell);
                }
            }
        }
        /// <summary>
        /// 初始化行
        /// </summary>
        /// <param name="gridview"></param>
        /// <param name="row"></param>
        /// <param name="fields"></param>
        protected static void InitializeRow(GridView gridview, GridViewRow row, DataControlField[] fields)
        {
            DataControlRowType rowType = row.RowType;
            DataControlRowState rowState = row.RowState;
            int rowIndex = row.RowIndex;
            bool useAccessibleHeader = false;

            TableCellCollection cells = row.Cells;
            string rowHeaderColumn = gridview.RowHeaderColumn;
            if (rowType == DataControlRowType.Header)
            {
                useAccessibleHeader = gridview.UseAccessibleHeader;
            }
            for (int i = 0; i < fields.Length; i++)
            {
                DataControlFieldCell cell;
                DataControlCellType header;
                if ((rowType == DataControlRowType.Header) && useAccessibleHeader)
                {
                    cell = new DataControlFieldHeaderCell(fields[i]);
                    ((DataControlFieldHeaderCell)cell).Scope = TableHeaderScope.Column;
                    ((DataControlFieldHeaderCell)cell).AbbreviatedText = fields[i].AccessibleHeaderText;
                }
                else
                {
                    BoundField field = fields[i] as BoundField;
                    if (((rowHeaderColumn.Length > 0) && (field != null)) && (field.DataField == rowHeaderColumn))
                    {
                        cell = new DataControlFieldHeaderCell(fields[i]);
                        ((DataControlFieldHeaderCell)cell).Scope = TableHeaderScope.Row;
                    }
                    else
                    {
                        cell = new DataControlFieldCell(fields[i]);
                    }
                }
                switch (rowType)
                {
                    case DataControlRowType.Header:
                        header = DataControlCellType.Header;
                        break;

                    case DataControlRowType.Footer:
                        header = DataControlCellType.Footer;
                        break;

                    default:
                        header = DataControlCellType.DataCell;
                        break;
                }
                fields[i].InitializeCell(cell, header, rowState, rowIndex);
                cells.Add(cell);
            }
        }