GrideView合并列合并序号,隐藏某列按钮

合并编号列 

/// <summary> 

    /// 合并GridView中某列相同信息的行(单元格) 

    /// </summary> 

    /// <param name="GridView1">GridView</param> 

    /// <param name="cellNum">第几列</param> 

    public static void FilLRowsNO(GridView GridView1, int cellNum)

    {

        int i = 0, rowSpanNum = 1;

        int no = 0;

        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[0].Visible = false;

                    rowSpanNum++;

                }

                else

                {

                    gvr.Cells[0].RowSpan = rowSpanNum;

                    no = no + 1;

                    gvr.Cells[0].Text = no.ToString();







                    rowSpanNum = 1;

                    break;

                }

                if (i == GridView1.Rows.Count - 1)

                {

                    gvr.Cells[0].RowSpan = rowSpanNum;

                    no = no + 1;

                    gvr.Cells[0].Text = no.ToString();



                }

            }

        }

    }

合并数据列

    /// <summary> 

    /// 合并GridView中某列相同信息的行(单元格) 

    /// </summary> 

    /// <param name="GridView1">GridView</param> 

    /// <param name="cellNum">第几列</param> 

    public static void GroupRows(GridView GridView1, int cellNum)

    {

        int i = 0, 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;

                }

            }

        }

    }

隐藏gridView里面最后一行绑定的linkbutton按钮



/// <summary> 

    /// 去掉gridview最后一行的button

    /// </summary> 

    /// <param name="GridView1">GridView</param> 

    /// <param name="cellNum">第几列</param> 

    public static void CoverRow(GridView GridView1)

    {

        int i = 0;

        int count = GridView1.Rows.Count;

        GridViewRow gvr = GridView1.Rows[count - 1];

        //数据生成

        LinkButton S1 = (LinkButton)gvr.FindControl("LinkButton6");

        LinkButton S2 = (LinkButton)gvr.FindControl("LinkButton7");

        LinkButton S3 = (LinkButton)gvr.FindControl("LinkButton8");

        LinkButton S4 = (LinkButton)gvr.FindControl("LinkButton9");

        LinkButton S5 = (LinkButton)gvr.FindControl("LinkButton10");

        LinkButton S6 = (LinkButton)gvr.FindControl("LinkButton11");

 

        S1.Visible = false;

        S2.Visible = false;

        S3.Visible = false;

        S4.Visible = false;

        S5.Visible = false;

        S6.Visible = false;

        

        

    }
View Code
 


主要是用到GridView的 GridViewRow这个属性

你可能感兴趣的:(grid)