博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
无尽的控件-GridView复合表头
阅读量:4569 次
发布时间:2019-06-08

本文共 1874 字,大约阅读时间需要 6 分钟。

 

首先说明下 复合表头 顾名思义 就是多个表头 弄在一起了(汗...)

总结来说  就是合并单元格 出来的效果 下面请看关键代码

 

 

protected void Page_Load(object sender, EventArgs e)    {        if (!Page.IsPostBack)        {            onload();        }    }    protected void onload()    {        GridView1.DataSource = new T().Get();        GridView1.DataBind();    }

上面的这个 我就不说了 就是绑定而已 但是大家可以看到 GridView里有个row_create事件,关键代码如下

protected void create(object sender, GridViewRowEventArgs e)    {        if (e.Row.RowType == DataControlRowType.Header)        {            TableCellCollection tcHeader = e.Row.Cells;            //清除自动生成的表头            tcHeader.Clear();            tcHeader.Add(new TableHeaderCell());            tcHeader[0].RowSpan = 2;            tcHeader[0].Text = "学号";                        tcHeader.Add(new TableHeaderCell());            tcHeader[1].ColumnSpan = 4;            tcHeader[1].Text = "学员资料";            tcHeader.Add(new TableHeaderCell());            tcHeader[2].RowSpan = 2;            tcHeader[2].Text = "入学时间";            tcHeader.Add(new TableHeaderCell());            tcHeader[3].RowSpan = 2;            tcHeader[3].Text = "籍贯";            tcHeader.Add(new TableHeaderCell());            tcHeader[4].Text = "姓名";            tcHeader.Add(new TableHeaderCell());            tcHeader[5].Text = "性别";            tcHeader.Add(new TableHeaderCell());            tcHeader[6].Text = "年龄";            tcHeader.Add(new TableHeaderCell());            tcHeader[7].Text = "密码";            for (int i = 0; i < 8; i++)            {                tcHeader[i].BackColor = System.Drawing.Color.Green;            }        }

最后的循环 是为了显示颜色用的 如果大家有固定的主题 或者样式 直接用就可以了 注释无压力

 

那么最后 效果图呢?

 

 

 

 

转载于:https://www.cnblogs.com/diaodiaop/archive/2012/04/25/2469734.html

你可能感兴趣的文章
程序中的日期格式
查看>>
大众点评CAT错误总结以及解决思路
查看>>
从0开始学爬虫3之xpath的介绍和使用
查看>>
Shell成长之路
查看>>
vim下正则表达式的非贪婪匹配
查看>>
一个python的计算熵(entropy)的函数
查看>>
spring源码学习——spring整体架构和设计理念
查看>>
模拟window系统的“回收站”
查看>>
报文格式【定长报文】
查看>>
RDLC报表钻取空白页问题
查看>>
多路电梯调度的思想
查看>>
jQuery-对Select的操作
查看>>
过滤器、监听器、拦截器的区别
查看>>
为什么要进行需求分析?通常对软件系统有哪些需求?
查看>>
一些模板
查看>>
jquery和dom元素相互转换
查看>>
放大的X--HDOJ-201307292012
查看>>
题目831-签到-nyoj-20140818
查看>>
百词斩-斩家秘籍
查看>>
Mysql主从配置,实现读写分离
查看>>