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));
}
}
ASPxGridView-单元格合并的更多相关文章
- ExtJS 4.2 Grid组件的单元格合并
ExtJS 4.2 Grid组件本身并没有提供单元格合并功能,需要自己实现这个功能. 目录 1. 原理 2. 多列合并 3. 代码与在线演示 1. 原理 1.1 HTML代码分析 首先创建一个Grid ...
- NPOI 教程 - 2.1单元格合并
来源:http://liyingchun343333.blog.163.com/blog/static/3579731620091018212990/ 合并单元格在制作表格时很有用,比如说表格的标题就 ...
- asp.net使用控件datagrid实现表头单元格合并
合并的要点: 1.datagid的单元格合并原理是table中tr,td的布局实现; 2.合并的时机实在其datagridcreate事件中实现; 3.认识一个对象TableCellCollectio ...
- DataGridView单元格合并
本文章转载:http://www.cnblogs.com/xiaofengfeng/p/3382094.html 图: 代码就是如此简单 文件下载:DataGridView单元格合并源码 也可以参考: ...
- devexpress实现单元格合并以及依据条件合并单元格
1.devexpress实现单元格合并非常的简单,只要设置属性[AllowCellMerge=True]就可以了,实现效果如下图: 2.但是在具体要求中并非需要所有的相同单元格都合并,可能需要其他的条 ...
- SNF快速开发平台MVC-表格单元格合并组件
1. 表格单元格合并组件 1.1. 效果展示 1.1.1. 页面展现表格合并单元格 图 4.1 1.1.2. 导出excel合并单元格 图 4.2 1.2. 调用说 ...
- 关于table动态添加数据 单元格合并 数组合并
var newArr = [ {"BranchID":1,"BranchName":"城二","BranchFullName&qu ...
- excel技巧--单元格合并与拆分
如果要将上图的地区列做成下图的合并单一列: 有如下做法: (以下图表格为例) 1.选择要排序的表格,点击“开始”-->排序和筛选-->自定义排序.在对话框选择“业务项目”进行排序: 2.选 ...
- element-ui table 最后一行合计,单元格合并
接着写两个方法--最后一行合计的方法 --单元格合并的方法 先写一个rowspan方法,计算出spanArr数组是怎么单元格合并的,注意rowspan方法要在渲染完成之前使用,可以在mounted中使 ...
- 如何通过DataGridView 实现单元格合并和二维表头
先看下实现出来的效果(这里随便写了几组数据,用来测试) 先初始一个DataGridView 设置哪几列 DataGridView 里男女这两列的 AutoSizeMode 可以设置Fill. publ ...
随机推荐
- RHEL Channel Bonding
1. 添加 kernel 模块 RHEL5上编辑 /etc/modprobe.conf 加入 alias bond0 bonding options bond0 miimon=100 mode=1 ...
- 【POJ】3264 Balanced Lineup ——线段树 区间最值
Balanced Lineup Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 34140 Accepted: 16044 ...
- wchar_t 、UTF-8、UTF-16的转换方法 - luketty的专栏 - 博客频道 - CSDN.NET
wchar_t .UTF-8.UTF-16的转换方法 - luketty的专栏 - 博客频道 - CSDN.NET wchar_t .UTF-8.UTF-16的转换方法
- CSU - 1356 Catch(dfs染色两种写法,和hdu4751比较)
Description A thief is running away! We can consider the city to N–. The tricky thief starts his esc ...
- 无线网破解软件|一键式破解无线网|BT17软件包下载[笔记本+软件就行]
从新版BT17发布到现在已经有一段时间,谢谢大家的一直来的关注.现在给大家讲解一下无线网破解问题,告诉 大家如何一键式破解WPA,WPA2,AES.Tkip等加密方式以及新版BT17软件包的下载地址. ...
- C# DataTable 详解
添加引用 using System.Data; 创建表 //创建一个空表 DataTable dt = new DataTable(); //创建一个名为"Table_New"的空 ...
- php 接收curl json 数据
curl -H "Content-Type: application/json" http://127.0.0.1:8000 -X POST -d 'xxxx' php $strP ...
- 使用jQuery出现the function undefined
出现function undefined往往是相关的JS文件没有导入导致,在相关文件都导入的情况下,使用jQuery提供的方法还会出现function undefined错误,或许就是jQuery对象 ...
- CPU核心数
Process.ProcessorAffinity 属性: public IntPtr ProcessorAffinity { get; set; }属性值:位掩码,表示关联进程内的线程可以在其上运行 ...
- Windows2008RT搭建VPN服务器
总结一下2008系统搭建VPN的步骤和过程,自己有个人网站和服务要通过互联网发布出来.服务器放在自己家里,宽带是民用的.也就产生了服务发布的一些问题.用无法映射出真实的公网IP,或是一些其他内部的问题 ...