• gridview自动求和及合并多列多行单元格


    自动求和代码如下:

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowIndex >= 0)
            {
                sum += Convert.ToInt32(e.Row.Cells[4].Text);
            }
            else if (e.Row.RowType == DataControlRowType.Footer)
            {
                e.Row.Cells[1].Text = "总分为:";
                e.Row.Cells[2].Text = sum.ToString();
                e.Row.Cells[3].Text = "平均分:";
                e.Row.Cells[4].Text = ((int)(sum / GridView1.Rows.Count)).ToString();
            }
        }

    合并相同的单元格:

    /// <summary>
        /// 判断gridview控件的相邻单元格中的数据是否相同,如果相同,则合并单元格
        /// </summary>
        private void gvRender()
        {
            if (GridView1.Rows.Count <= 1)
            {
                return;
            }

            for (int i = 0; i < GridView1.Columns.Count; i++)
            {
                TableCell tc = GridView1.Rows[0].Cells[i];
                for (int j = 1; j < GridView1.Rows.Count; j++)
                {
                    TableCell newtc = GridView1.Rows[j].Cells[i];
                    if (newtc.Text == tc.Text)      //判断当前列相邻的单元格的内容是否相同
                    {
                        newtc.Visible = false;      //如果相同则隐藏其中一个单元格
                        if (tc.RowSpan == 0)       
                        {
                            tc.RowSpan = 1;
                        }
                        tc.RowSpan++;
                        tc.VerticalAlign = VerticalAlign.Middle;
                    }
                }
            }
        }

    记得将ShowFooter设置为true哦;

  • 相关阅读:
    Docker实践之03-Dockerfile指令详解
    Docker实践之02-使用镜像及定制
    通过Hack方式实现SDC中Stage配置联动刷新
    多级部门查询性能问题解决方案
    Docker实践之01-入门介绍
    从阿里腾讯2朵云产品中学到的用户体验
    HttpClient在多线程环境下踩坑总结
    一次对JDK进行"减肥"的记录
    北京西站如何进站接人
    多实例集群部署下的图片上传和访问
  • 原文地址:https://www.cnblogs.com/xlhblogs/p/2307142.html
Copyright © 2020-2023  润新知