gridview合并单元格

由于项目要求,需要合并某些单元格,因此特意封装了如下帮助类:

  /// <summary>
/// 合并单元格
/// </summary>
public class MergeCellHelper
{
/// <summary>
/// 合并表头
/// </summary>
/// <param name="row">当前行</param>
/// <param name="startColumn">开始列</param>
/// <param name="endColumn">结束列</param>
public static void MergeHeader(GridViewRow row, int startColumn, int endColumn)
{
for (int i = startColumn; i <= endColumn; i++)
{
if (i != startColumn)
{
row.Cells[i].Visible = false;
continue;
}
row.Cells[startColumn].ColumnSpan = endColumn - startColumn + ;
}
} /// <summary>
/// 合并指定列的行
/// </summary>
/// <param name="gv">gridview</param>
/// <param name="columns">指定的列:可以多列</param>
public static void MergeRow(GridView gv, params int[] columns)
{
MergeRowByReferenceColumn(gv, , columns);
} /// <summary>
/// 合并指定列的行(参考列一定要合理,慎用)
/// </summary>
/// <param name="gv">gridview</param>
/// /// <param name="referenceColumn">参照列</param>
/// <param name="columns">指定的列:可以多列</param>
public static void MergeRowByReferenceColumn(GridView gv, int referenceColumn, params int[] columns)
{
for (int i = ; i < columns.Length; i++)
{
var currentColumn = columns[i];
int rowSpan = ;
for (int j = ; j < gv.Rows.Count; j++)
{
var currentRow = gv.Rows[j];
if (j < gv.Rows.Count - )
{
var nextRow = gv.Rows[j + ];
if (currentRow.Cells[referenceColumn].Text == nextRow.Cells[referenceColumn].Text)
{
if (currentRow.Cells[currentColumn].Text == nextRow.Cells[currentColumn].Text)
{
rowSpan = rowSpan < ? : rowSpan + ;
nextRow.Cells[currentColumn].Visible = false;
}
else
{
gv.Rows[j - rowSpan + ].Cells[currentColumn].RowSpan = rowSpan;
rowSpan = ;
}
}
else
{
gv.Rows[j - rowSpan + ].Cells[currentColumn].RowSpan = rowSpan;
rowSpan = ;
}
}
else
{
gv.Rows[j - rowSpan + ].Cells[currentColumn].RowSpan = rowSpan;
rowSpan = ;
}
}
}
} }

webform gridview合并单元格的更多相关文章

  1. gridview 合并单元格 并原样导出数据

    使用的方式都是比较简单的,asp.net 如何进行数据的导出有好多种方法,大家可以在网上找到, 一下提供一些合并并原样输出的一个简单的代码: public void ToExcel(System.We ...

  2. gridview合并单元格

    记录用,以前写过,忘记了转自:http://marss.co.ua/MergingCellsInGridView.aspx public class GridDecorator { public st ...

  3. DEV gridview 合并单元格

    private void gv_docargo_CellMerge(object sender, DevExpress.XtraGrid.Views.Grid.CellMergeEventArgs e ...

  4. gridview 合并单元格后,选中颜色重新绘制

    gv_docargo.RowStyle += OnRowStyle; private void OnRowStyle(object sender, DevExpress.XtraGrid.Views. ...

  5. GRIDVIEW多行多列合并单元格(合并列)

    GitHub项目地址:https://github.com/mingceng/merge-gridviewcell 去年的时候,我写了两篇文章:  GridView多行多列合并单元格(完整代码和例子) ...

  6. GridView中合并单元格

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Da ...

  7. GridView相同内容合并单元格

    using System;using System.Data;using System.Configuration;using System.Collections;using System.Web; ...

  8. Repeater多列分别合并单元格

    GridView.Repeater合并单元格可以参考http://www.cnblogs.com/zhmore/archive/2009/04/22/1440979.html,但是原文例子是合并一列的 ...

  9. .Net用字符串拼接实现表格数据相同时合并单元格

    前言 最近在做项目通过GridView或Repeater绑定数据,如果两行或若干行某列值相同,需要进行合并单元格,但是实现过程中想到了字符串拼接,于是就没用绑定数据控件,而是用了html结合字符串实现 ...

随机推荐

  1. 88. Merge Sorted Array 后插

    合并两个排序的整数数组A和B变成一个新的数组.给出A=[1,2,3,4],B=[2,4,5,6],返回 [1,2,2,3,4,4,5,6] 假设A具有足够的空间(A数组的大小大于或等于m+n)去添加B ...

  2. 全排列12 · Permutations

    无重复 [抄题]: Given a collection of numbers, return all possible permutations. For example,[1,2,3] have ...

  3. [leetcode]333. Largest BST Subtree最大二叉搜索树子树

    Given a binary tree, find the largest subtree which is a Binary Search Tree (BST), where largest mea ...

  4. Maven核心简析

    本文以类图的方式,介绍maven核心的12个概念以及相互之间的关系. Table of Contents 1 maven管理的目标:工程(Project) 1.1 工程依赖关系 1.2 工程聚合关系 ...

  5. discuz的css处理机制

    common/common.css 是一个通用的css文件. common/module.css 是某个功能模块使用的css文件.   module.css中,利用特殊语法: /** 标识 **/ c ...

  6. 移动端web及app设计尺寸

    转载 2017年07月27日 22:48:16 984 移动端高清.多屏适配方案 背景 开发移动端H5页面 面对不同分辨率的手机 面对不同屏幕尺寸的手机 视觉稿 在前端开发之前,视觉MM会给我们一个p ...

  7. C语言基础课第四次作业

    1.实验代码      7-2 打印九九口诀表 (15 分) #include<stdio.h> #include<math.h> int main(void){ int a, ...

  8. hdu-1050(贪心+模拟)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050 思路:由图可知,1对应2,3对应4,以此类推,如果x,y是偶数则变为奇数: 每次输入两个区间,找 ...

  9. hadoop学习笔记(二):centos7三节点安装hadoop2.7.0

    环境win7+vamvare10+centos7 一.新建三台centos7 64位的虚拟机 master node1 node2 二.关闭三台虚拟机的防火墙,在每台虚拟机里面执行: systemct ...

  10. jedis 链接池使用(转)

    Jedis作为redis的最佳客户端,它提供了连接池的特性,“连接池”在通常情况下可以有效的提高应用的通信能力,并且这是一种良好的设计模式.Jedis的连接池设计基于apache commons-po ...