private void ShowNullTable(GridView grd)
{
if (grd.Rows.Count > 0) return; //有数据,不要处理
if (grd.DataSource != null)
{
if (((DataTable)grd.DataSource).Rows.Count > 0)
{
return;
}
}
GridViewRow row = new GridViewRow(-1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal);
foreach (DataControlField field in grd.Columns)
{
TableCell cell = new TableCell();
cell.Text = field.HeaderText;
cell.Width = field.HeaderStyle.Width;
cell.Height = field.HeaderStyle.Height;
cell.ForeColor = field.HeaderStyle.ForeColor;
cell.Font.Size = field.HeaderStyle.Font.Size;
cell.Font.Bold = field.HeaderStyle.Font.Bold;
cell.Font.Name = field.HeaderStyle.Font.Name;
cell.Font.Strikeout = field.HeaderStyle.Font.Strikeout;
cell.Font.Underline = field.HeaderStyle.Font.Underline;
cell.BackColor = field.HeaderStyle.BackColor;
cell.VerticalAlign = field.HeaderStyle.VerticalAlign;
cell.HorizontalAlign = field.HeaderStyle.HorizontalAlign;
cell.CssClass = field.HeaderStyle.CssClass;
cell.BorderColor = field.HeaderStyle.BorderColor;
cell.BorderStyle = field.HeaderStyle.BorderStyle;
cell.BorderWidth = field.HeaderStyle.BorderWidth;
row.Cells.Add(cell);
}
TableItemStyle headStyle = grd.HeaderStyle;
TableItemStyle emptyStyle = grd.EmptyDataRowStyle;
emptyStyle.Width = headStyle.Width;
emptyStyle.Height = headStyle.Height;
emptyStyle.ForeColor = headStyle.ForeColor;
emptyStyle.Font.Size = headStyle.Font.Size;
emptyStyle.Font.Bold = headStyle.Font.Bold;
emptyStyle.Font.Name = headStyle.Font.Name;
emptyStyle.Font.Strikeout = headStyle.Font.Strikeout;
emptyStyle.Font.Underline = headStyle.Font.Underline;
emptyStyle.BackColor = headStyle.BackColor;
emptyStyle.VerticalAlign = headStyle.VerticalAlign;
emptyStyle.HorizontalAlign = headStyle.HorizontalAlign;
emptyStyle.CssClass = headStyle.CssClass;
emptyStyle.BorderColor = headStyle.BorderColor;
emptyStyle.BorderStyle = headStyle.BorderStyle;
emptyStyle.BorderWidth = headStyle.BorderWidth;
if (grd.Controls.Count == 0)
{
grd.Page.Response.Write("<script language='javascript'>alert('必须在初始化表格类之前执行DataBind方法并设置EmptyDataText属性不为空!');</script>");
}
else
{
grd.Controls[0].Controls.Clear(); //删除没数据时的提示
grd.Controls[0].Controls.AddAt(0, row);
GridViewRow newRow = new GridViewRow(0, 0, DataControlRowType.DataRow, DataControlRowState.Normal);
newRow.Cells.Add(new TableCell());
newRow.Cells[0].ColumnSpan = Columns.Count;
newRow.Cells[0].HorizontalAlign = HorizontalAlign.Center;
newRow.Cells[0].Text = EmptyDataText;
grd.Controls[0].Controls.Add(newRow);
}
}
分享到:
相关推荐
layui js 动态加载数据 复杂表头多表头实例
给DataGridView表头添加下拉列表实现数据过滤,附上修改功能代码,实现选择性添加下拉选择。
labview给Excel数据表格加表头
将PB中数据窗口导出EXCEL,所见即所得
asp.net 导入excel时,处理合并表头、复杂表头、多行表头 1.解决复杂表头的Excel导入。可以解决任何复杂的表头。 2.导入时,显示请稍后。。。提醒框,完毕后会自动隐藏 3.全面扫描Excel数据,将所有异常详细信息写入...
layui数据表格 demo,静态数据库加载表头不固定 的数据展示方式;
Excel选中数据进行导出时不需要导出表头。
支持从数据库中查询到数据,以多级表头形式导入到Excel文件中。比如:一级表头:学号、姓名、各科成绩。二级表头:语文、数学、英语(二级表头在各科成绩下面)。
spreadjs_动态添加表头及数据绑定-demo
在开发swing时,JTble不显示表头的问题
一行代码搞定layui数据表格的表头checkbox复选框隐藏问题。
实时采集数据保存到Excel中,并加上合适的,自定义的表头
实现C语言数据结构标头的插入,对单链表的学习有用
//表头1 要合并的格表头描述字段 已@分割 注意 这里的表头是至第一行表头 var gauge_head2="日期@交易量汇总@设备占比@WEB占比@APP占比@互生币支付@互商订单支付@代兑互生币@兑换互生币@货币转银行";// 表头描述...
利用For循环连续读取数据,将数组转换为动态数据,设置单路动态数据的属性,然后合并多路信号(相当于填入Excel某sheet中不同列),然后利用”写入测量文件“把读取数据和相应时间戳写入Excel中,下面用随机数代替...
A.详情见readme.txt ...3.可以添加多张表格,每个表格是独立的,它们都有属于自己的自定义表头。 4.表头的右键操作我是自己写的,也可以用原例的方式,不过要复杂一点。 5.每一张表,一个tab,tab可以鼠标左击关闭
QT表头支持多列显示,功能强大,代码有点难度,下载的同学好好研究一下,并且字体显示有乱码,自行解决,不影响功能
自定义表头,添加复选框和下拉选项框
使用注解导入导出各类多表头,单表头,及各种导入数据验证(含非空,字符长度,数据包含与排他,正则验证及自定义验证(使用数据库操作)等)的i简单工具类
DataGridView 表头添加筛选功能,类似Excel列筛选功能 VS2013 创建项目