Gridview数据显示实现按日期排序分割线

前段时间做个小项目需要查询结果按日期排序并将显示结果每天数据之间用明显的分割线隔开

效果如下:

具体实现方法其实很简单:

Gridview数据绑定时添加方法: OnRowDataBound="GridView1_RowDataBound";

具体实现就在这个方法里

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.RowIndex != 0)
            {
                try
                {
                    if (e.Row.Cells[3].Text.ToString().Remove(10) == Session["222"].ToString())//显示日期数据是否有Session记录
                    {
                    }
                    else
                    {
                        if (e.Row.RowIndex == 0)//清除第一行显示
                        { }
                        else
                        {
                            foreach (TableCell cell in e.Row.Cells)
                            {
                                cell.Attributes.Add("style", " border-top:solid 3px #6CF");
                            }
                        }
                    }
                }
                catch { }
 
                Session["222"] = e.Row.Cells[3].Text.ToString().Remove(10);//记录Session为传递过来的日期
            }
        }
    }

  

posted on 2012-11-05 17:00  小东北  阅读(1214)  评论(0编辑  收藏  举报