返回顶部

收藏

c# GridView合并单元格

更多

GridView合并单元格

    //GridView合并单元格
  //中间变量,存取TableCell
    private TableCell publishDateCell = null;
    protected void grvTest_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //第一行,publishDateCell=null 
            if (publishDateCell == null)
            {
                publishDateCell = e.Row.Cells[2];
                publishDateCell.RowSpan = 1;
            }
            else
            {
                //判断当前行的日期是否和publishDateCell一致
                //如果一致,跨行
                if (e.Row.Cells[2].Text == publishDateCell.Text)
                {
                    e.Row.Cells[2].Visible = false;
                    publishDateCell.RowSpan++;
                }
                else
                {
                    //如果不等,更新publishDateCell为当前日期
                    //重新统计跨行
                    publishDateCell = e.Row.Cells[2];
                    publishDateCell.RowSpan = 1;
                }
            }
        }
    }

标签:c#,GridView

收藏

0人收藏

支持

0

反对

0

发表评论