GridView的行合并

WEB的GRIDVIEW的行合并及列合并,这次做的这个思路是较为清晰可行的。

推荐给大家。

protected void GridView4_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#D6E0F2'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
            }
            if (e.Row.DataItem != null)
            {
                if (string.IsNullOrEmpty((e.Row.DataItem as DataRowView)["Content2"].ToString().Trim()))
                {
                    e.Row.Cells[3].ColumnSpan = 2;
                    e.Row.Cells[4].Visible = false;
                }
                if (e.Row.DataItemIndex > 0)
                {
                    //范围  RowSpan
                    string curRowValue = (e.Row.DataItem as DataRowView)["PriceArea"].ToString().Trim();
                    string preRowValue = "";
                    preRowValue = (GridView4.Rows[e.Row.RowIndex - 1].FindControl("Label2") as Label).Text.Trim();

                    if (preRowValue.Equals(curRowValue))
                    {
                        GridViewRow gvr = e.Row;
                        gvr.Cells[2].Visible = false;
                        for (int ci = e.Row.RowIndex - 1; ci >= 0; ci--)
                        {
                            if (GridView4.Rows[ci].Cells[2].Visible)
                            {
                                if (GridView4.Rows[ci].Cells[2].RowSpan == 0)
                                    GridView4.Rows[ci].Cells[2].RowSpan = 2;
                                else
                                    GridView4.Rows[ci].Cells[2].RowSpan++;
                                break;
                            }
                        }
                    }
                    else
                    {
                        e.Row.Cells[2].Visible = true;
                    }
                    //类别1  RowSpan
                    string curRowValue2 = (e.Row.DataItem as DataRowView)["Content1"].ToString().Trim();
                    string preRowValue2 = "";
                    preRowValue2 = (GridView4.Rows[e.Row.RowIndex - 1].FindControl("class1") as Label).Text.Trim();
                    if (preRowValue2.Equals(curRowValue2))
                    {
                        GridViewRow gvr = e.Row;
                        gvr.Cells[3].Visible = false;
                        for (int ci = e.Row.RowIndex - 1; ci >= 0; ci--)
                        {
                            if (GridView4.Rows[ci].Cells[3].Visible)
                            {
                                if (GridView4.Rows[ci].Cells[3].RowSpan == 0)
                                    GridView4.Rows[ci].Cells[3].RowSpan = 2;
                                else
                                    GridView4.Rows[ci].Cells[3].RowSpan++;
                                break;
                            }
                        }
                    }
                    else
                    {
                        e.Row.Cells[3].Visible = true;
                    }
                    //经管岗位  RowSpan
                    string curRowValue3 = (e.Row.DataItem as DataRowView)["AdminPost"].ToString().Trim();
                    string preRowValue3 = "";
                    preRowValue3 = (GridView4.Rows[e.Row.RowIndex - 1].FindControl("Label4") as Label).Text.Trim();
                    if (preRowValue3.Equals(curRowValue3))
                    {
                        GridViewRow gvr = e.Row;
                        gvr.Cells[5].Visible = false;
                        for (int ci = e.Row.RowIndex - 1; ci >= 0; ci--)
                        {
                            if (GridView4.Rows[ci].Cells[5].Visible)
                            {
                                if (GridView4.Rows[ci].Cells[5].RowSpan == 0)
                                    GridView4.Rows[ci].Cells[5].RowSpan = 2;
                                else
                                    GridView4.Rows[ci].Cells[5].RowSpan++;
                                break;
                            }
                        }
                    }
                    else
                    {
                        e.Row.Cells[5].Visible = true;
                    }
                    
                }
            }
        }

具体效果如图



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值