惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Hackread – Cybersecurity News, Data Breaches, AI and More
W
WeLiveSecurity
C
Check Point Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost
GbyAI
GbyAI
A
Arctic Wolf
NISL@THU
NISL@THU
N
Netflix TechBlog - Medium
The Register - Security
The Register - Security
M
MIT News - Artificial intelligence
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Microsoft Security Blog
Microsoft Security Blog
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
T
Tenable Blog
G
GRAHAM CLULEY
O
OpenAI News
S
Schneier on Security
Google Online Security Blog
Google Online Security Blog
Vercel News
Vercel News
宝玉的分享
宝玉的分享
Attack and Defense Labs
Attack and Defense Labs
T
The Blog of Author Tim Ferriss
量子位
aimingoo的专栏
aimingoo的专栏
The Cloudflare Blog
P
Privacy & Cybersecurity Law Blog
S
SegmentFault 最新的问题
MongoDB | Blog
MongoDB | Blog
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
LINUX DO - 热门话题
博客园_首页
F
Full Disclosure
Recent Commits to openclaw:main
Recent Commits to openclaw:main
D
Docker
U
Unit 42
A
About on SuperTechFans
博客园 - 司徒正美
Hacker News - Newest:
Hacker News - Newest: "LLM"
人人都是产品经理
人人都是产品经理
Application and Cybersecurity Blog
Application and Cybersecurity Blog
G
Google Developers Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
J
Java Code Geeks
云风的 BLOG
云风的 BLOG
Scott Helme
Scott Helme
TaoSecurity Blog
TaoSecurity Blog

博客园 - Achilles.NET

路过 通过javascript获得当前窗口页面的宽高度 SQL SERVER设置重新构造字段值大小写敏感 - Achilles.NET - 博客园 修改SQL默认不区分大小写字段值规则 [转帖]Transact-SQL编程规范 Version 1.1 C#调用存储过程返回值 - Achilles.NET - 博客园 Ghost备份后找不到gho镜像文件的解决办法 GridView数据突出颜色显示解决办法 Temple js控制标题闪动 山西DOT NET俱乐部 WEB弹出窗口打印 打印脚本 DataGrid分页 妻子让老公死心塌地的绝招 下班无聊,随便YY const(C# 参考) ERP──Enterprise Resource Planning 企业资源计划系统 extern(C# 参考)
GridView中空记录不显示表头的解决方案[作者不祥]
Achilles.NET · 2007-07-06 · via 博客园 - Achilles.NET

在DataGrid中,我们可以把一个包含空记录的DataSet或DataTable绑定给DataGrid,这样,呈现时,DataGrid会把数据源中的字段定义以表头的形式显示出来。

在GridView控件中,却不会显示,如果DataSet或DataTable是空记录。则GridView连表头都不显示。
只能通过变通的方法实现,稍微有一些麻烦:

    public void BuildNoRecords(GridView gridView, DataSet ds)

    {

        if (ds.Tables[0].Rows.Count == 0)

        {

            ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());

            gridView.DataSource = ds;

            gridView.DataBind();

            int columnCount = gridView.Rows[0].Cells.Count;

            gridView.Rows[0].Cells.Clear();

            gridView.Rows[0].Cells.Add(new TableCell());

            gridView.Rows[0].Cells[0].ColumnSpan = columnCount;

            gridView.Rows[0].Cells[0].Text = "No Records Found.";

        }

        else

        {

            gridView.DataSource = ds;

            gridView.DataBind();

        }

    }