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

转载于:https://www.cnblogs.com/devercai/p/4108094.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值