GridView 合并单元格(多列)及特定条件的数据高亮显示实现
2011-11-25 09:11
417 查看
效果图如下:
![](http://hi.csdn.net/attachment/201111/25/209776_1322183352gSZl.jpg)
代码:
后台:
![](http://hi.csdn.net/attachment/201111/25/209776_1322183352gSZl.jpg)
代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Demo.aspx.cs" Inherits="WebApplication1.Demo" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Tim Demo 演示</title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" onrowdatabound="GridView1_RowDataBound"> </asp:GridView> </div> </form> </body> </html>
后台:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Drawing; namespace WebApplication1 { public partial class Demo : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindData(); } } void BindData() { var list = new List<Temp> { new Temp{ SiteName="千灯浦口",Time="2011-9-23",Function=Fun.自动值.ToString(), CODMn="4.10", TOC="6.83",pH="7.10"}, new Temp{ SiteName="千灯浦口",Time="2011-9-23",Function=Fun.手工值.ToString(), CODMn="4.2", TOC="6.34",pH="7.3"}, new Temp{ SiteName="千灯浦口",Time="2011-9-23",Function=Fun.偏差.ToString(), CODMn="-2.38%", TOC="7.73%",pH="-2.74%"}, new Temp{ SiteName="石浦大桥",Time="2011-9-23",Function=Fun.自动值.ToString(), CODMn="3.9", TOC="6.38",pH="7.18"}, new Temp{ SiteName="石浦大桥",Time="2011-9-23",Function=Fun.手工值.ToString(), CODMn="5.1", TOC="6.08",pH="6.99"}, new Temp{ SiteName="石浦大桥",Time="2011-9-23",Function=Fun.偏差.ToString(), CODMn="-23.53%", TOC="4.93%",pH="2.72%"}, new Temp{ SiteName="朱军港口",Time="2011-9-23",Function=Fun.自动值.ToString(), CODMn="3.30", TOC="6.43",pH="6.64"}, new Temp{ SiteName="朱军港口",Time="2011-9-23",Function=Fun.手工值.ToString(), CODMn="3.5", TOC="5.88",pH="7.02"}, new Temp{ SiteName="朱军港口",Time="2011-9-23",Function=Fun.偏差.ToString(), CODMn="-5.71%", TOC="9.35%",pH="-5.41%"} }; GridView1.DataSource = list; GridView1.DataBind(); } enum Fun { 自动值, 手工值, 偏差 }; string _tempvalue = ""; int _temprowspan = 1; TableCell _temptablecell = null; TableCell _temptablecell2 = null; protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Footer) { if (e.Row.Cells[0].Text == _tempvalue) { _temprowspan++; e.Row.Cells.Remove(e.Row.Cells[0]); e.Row.Cells.Remove(e.Row.Cells[0]); } else { if (_temprowspan != 1) { _temptablecell.RowSpan = _temprowspan; _temptablecell2.RowSpan = _temprowspan; } _tempvalue = e.Row.Cells[0].Text; _temptablecell = e.Row.Cells[0]; _temptablecell2 = e.Row.Cells[1]; _temprowspan = 1; } if (e.Row.Cells[3].Text == "7.3") { e.Row.Cells[3].BackColor = Color.Red; } } } } class Temp { public string SiteName { get; set; } public string Time { get; set; } public string Function { get; set; } public string CODMn { get; set; } public string TOC { get; set; } public string pH { get; set; } } }
相关文章推荐
- GridView 合并单元格(多列)及特定条件的数据高亮显示实现
- Gridview相关颜色显示(满足特定数据要求的颜色显示,高亮显示)
- Gridview某一列根据不同的条件显示不同颜色的实现(原创)
- aspnet中通过多条件筛选来显示数据的实现
- Gridview使用CheckBox全选与单选采用js实现同时高亮显示选择行
- 实现鼠标悬停高亮显示---分别在gridview和datagrid中
- jquery+ashx无刷新GridView数据显示插件(实现分页、排序、过滤功能)
- 关于在GridView模版里添加DropDownList实现根据下拉列表的不同选择gridview根据条件筛选显示。
- GridView控件实现数据的显示和删除(第8节)
- php从PostgreSQL 数据库检索数据,实现分页显示以及根据条件查找数据
- jquery+ashx无刷新GridView数据显示插件(实现分页、排序、过滤功能)
- 【Lucene】使用EasyUI和JQuery配合Lucene实现数据的分页查询以及高亮显示
- 我的ASPxGridView控件的数据是在后台绑定的,但是实现不了筛选和分页的功能,只能显示一页的数据?
- flex实现DataGrid高亮显示数据的功能
- ASP.NET GridView 实现课程表显示(动态合并单元格)
- 如何实现GridView控件分页显示数据
- 【Lucene】使用EasyUI和JQuery配合Lucene实现数据的分页查询以及高亮显示
- flex实现DataGrid高亮显示数据功能的解决方案
- ASP.NET GridView 实现课程表显示(动态合并单元格)实现步骤
- PHP实现从PostgreSQL数据库检索数据分页显示及根据条件查找数据示例