zoukankan      html  css  js  c++  java
  • 对gridview的小改动

    ///


        /// 合并某列内容相同的行
        ///

        ///
        ///
        public static void GroupRows(GridView GridView1, int cellNum)
        {
            int i = 0;
            int rowSpanNum = 1;

            while (i < GridView1.Rows.Count - 1)
            {
                GridViewRow gvr = GridView1.Rows[i];

                for (++i; i < GridView1.Rows.Count; i++)
                {
                    GridViewRow gvrNext = GridView1.Rows[i];

                    if (gvr.Cells[cellNum].Text == gvrNext.Cells[cellNum].Text)
                    {
                        gvrNext.Cells[cellNum].Visible = false;
                        rowSpanNum++;
                    }
                    else
                    {
                        gvr.Cells[cellNum].RowSpan = rowSpanNum;
                        rowSpanNum = 1;

                        break;
                    }

                    if (i == GridView1.Rows.Count - 1)
                    {
                        gvr.Cells[cellNum].RowSpan = rowSpanNum;
                    }
                }
            }
        }

    protected void gvMain_DataBound(object sender, EventArgs e)
        {
            GroupRows(this.gvMain, 1);

        }

    //加合计行

    protected void gvMain_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType != DataControlRowType.Footer && e.Row.RowType != DataControlRowType.Header)
            {
                DataRowView drv = (DataRowView)e.Row.DataItem;

                iNumber = Convert.ToInt32(drv[4]);
                totalNumber += iNumber;
            }
            if (e.Row.RowType == DataControlRowType.Footer) 
            {
                e.Row.Cells[4].Text = string.Format("{0}", totalNumber);
                e.Row.Cells[1].Text = "合计";
                e.Row.Cells[3].Visible = false;
                e.Row.Cells[1].ColumnSpan = 2;
                e.Row.Height = 32;
            }
        }

    欢迎拍砖,欢迎转载,欢迎关注,欢迎联系,就是各种欢迎
  • 相关阅读:
    [Codeforces 1178D]Prime Graph (思维+数学)
    [Codeforces 316E3]Summer Homework(线段树+斐波那契数列)
    [Codeforces 997C]Sky Full of Stars(排列组合+容斥原理)
    [HDU 3625]Examining the Rooms (第一类斯特林数)
    [Codeforces 364D]Ghd(随机算法+gcd)
    【快速幂】POJ3641
    【二分查找】POJ2456-Aggressive cows
    【判断解是否可行-二分】POJ1064-Cable master
    【动态规划/递推】BZOJ1806[IOI2007]- Miners
    【动态规划去除冗余】NOIP2010-乌龟棋
  • 原文地址:https://www.cnblogs.com/EddyPeng/p/1225883.html
Copyright © 2011-2022 走看看