国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

ASPxGridView-單元格合并

2019-11-17 01:52:40
字體:
來源:轉載
供稿:網友

aspxGridView-單元格合并

<dx:ASPxGridView ID="gridView" runat="server" ClientInstanceName="gvResults" Width="550px" AutoGenerateColumns="True" KeyFieldName="OrderID" DataSourceID="accessDataSource1"></dx:ASPxGridView><asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/nwind.mdb" SelectCommand="SELECT * FROM [Orders]"></asp:AccessDataSource>

<script type="text/javascript"> window.__OriginalDXUpdateRowCellsHandler = ASPxClientTableFixedColumnsHelper.PRototype.ChangeCellsVisibility; ASPxClientTableFixedColumnsHelper.prototype.ChangeCellsVisibility = function(row, startIndex, endIndex, display) { if((row.cells.length == 0) || (row.cells[0].getAttribute("ci") == null)) window.__OriginalDXUpdateRowCellsHandler(row, startIndex, endIndex - 1, display); // base call else { //custom processing for(var i = startIndex; i <= endIndex; i++) { var cell = FindCellWithColumnIndex(row, i); if(cell != null) cell.style.display = display; } } }; function FindCellWithColumnIndex(row, colIndex) { for(var i = 0; i < row.cells.length; i++) { if(row.cells[i].getAttribute("ci") == colIndex) return row.cells[i]; } return null; }=================================

protected void Page_Load(object sender, EventArgs e) { if (!(IsPostBack || IsCallback)) gridView.DataBind(); new ASPxGridViewCellMerger(gridView); gridView.Columns[0].FixedStyle = GridViewColumnFixedStyle.Left; gridView.Columns[1].FixedStyle = GridViewColumnFixedStyle.Left; gridView.Columns[0].CellStyle.BackColor = Color.FromArgb(0xEE, 0xEE, 0xEE); gridView.Columns[1].CellStyle.BackColor = Color.FromArgb(0xEE, 0xEE, 0xEE); gridView.Settings.ShowHorizontalScrollBar = true; }

===========CellMerger.cs=====================

using System;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using DevExpress.Web.ASPxGridView;using System.Collections.Generic;public class ASPxGridViewCellMerger { ASPxGridView grid; Dictionary<GridViewDataColumn, TableCell> mergedCells = new Dictionary<GridViewDataColumn, TableCell>(); Dictionary<TableCell, int> cellRowSpans = new Dictionary<TableCell, int>(); public ASPxGridViewCellMerger(ASPxGridView grid) { this.grid = grid; Grid.HtmlRowCreated += new ASPxGridViewTableRowEventHandler(grid_HtmlRowCreated); Grid.HtmlDataCellPrepared += new ASPxGridViewTableDataCellEventHandler(grid_HtmlDataCellPrepared); } public ASPxGridView Grid { get { return grid; } } void grid_HtmlDataCellPrepared(object sender, ASPxGridViewTableDataCellEventArgs e) { //add the attribute that will be used to find which column the cell belongs to e.Cell.Attributes.Add("ci", e.DataColumn.VisibleIndex.ToString()); if (cellRowSpans.ContainsKey(e.Cell)) { e.Cell.RowSpan = cellRowSpans[e.Cell]; } } void grid_HtmlRowCreated(object sender, ASPxGridViewTableRowEventArgs e) { if (Grid.GetRowLevel(e.VisibleIndex) != Grid.GroupCount) return; for (int i = e.Row.Cells.Count - 1; i >= 0; i--) { DevExpress.Web.ASPxGridView.Rendering.GridViewTableDataCell dataCell = e.Row.Cells[i] as DevExpress.Web.ASPxGridView.Rendering.GridViewTableDataCell; if (dataCell != null) { MergeCells(dataCell.DataColumn, e.VisibleIndex, dataCell); } } } void MergeCells(GridViewDataColumn column, int visibleIndex, TableCell cell) { bool isNextTheSame = IsNextRowHasSameData(column, visibleIndex); if (isNextTheSame) { if (!mergedCells.ContainsKey(column)) { mergedCells[column] = cell; } } if (IsPrevRowHasSameData(column, visibleIndex)) { ((TableRow)cell.Parent).Cells.Remove(cell); if (mergedCells.ContainsKey(column)) { TableCell mergedCell = mergedCells[column]; if (!cellRowSpans.ContainsKey(mergedCell)) { cellRowSpans[mergedCell] = 1; } cellRowSpans[mergedCell] = cellRowSpans[mergedCell] + 1; } } if (!isNextTheSame) { mergedCells.Remove(column); } } bool IsNextRowHasSameData(GridViewDataColumn column, int visibleIndex) { //is it the last visible row if (visibleIndex >= Grid.VisibleRowCount - 1) return false; return IsSameData(column.FieldName, visibleIndex, visibleIndex + 1); } bool IsPrevRowHasSameData(GridViewDataColumn column, int visibleIndex) { ASPxGridView grid = column.Grid; //is it the first visible row if (visibleIndex <= Grid.VisibleStartIndex) return false; return IsSameData(column.FieldName, visibleIndex, visibleIndex - 1); } bool IsSameData(string fieldName, int visibleIndex1, int visibleIndex2) { // is it a group row? if (Grid.GetRowLevel(visibleIndex2) != Grid.GroupCount) return false; return object.Equals(Grid.GetRowValues(visibleIndex1, fieldName), Grid.GetRowValues(visibleIndex2, fieldName)); }}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 皋兰县| 南皮县| 楚雄市| 丹巴县| 军事| 正定县| 大余县| 宜君县| 亚东县| 多伦县| 桃园市| 霍城县| 高清| 博野县| 子长县| 华容县| 泰安市| 新余市| 呼和浩特市| 太谷县| 山东省| 通化市| 姜堰市| 都匀市| 明星| 东港市| 东丰县| 山丹县| 赞皇县| 伊吾县| 蓬溪县| 郓城县| 凤阳县| 旌德县| 文安县| 东辽县| 双鸭山市| 长沙市| 武功县| 扶绥县| 宾阳县|