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

推荐订阅源

P
Proofpoint News Feed
WordPress大学
WordPress大学
Help Net Security
Help Net Security
Jina AI
Jina AI
Security Latest
Security Latest
Y
Y Combinator Blog
Project Zero
Project Zero
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
GbyAI
GbyAI
Know Your Adversary
Know Your Adversary
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
NISL@THU
NISL@THU
Cisco Talos Blog
Cisco Talos Blog
博客园 - 司徒正美
MyScale Blog
MyScale Blog
Cyberwarzone
Cyberwarzone
D
Docker
T
The Blog of Author Tim Ferriss
G
Google Developers Blog
C
CERT Recently Published Vulnerability Notes
B
Blog
L
LangChain Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
SecWiki News
SecWiki News
The Hacker News
The Hacker News
C
Check Point Blog
L
Lohrmann on Cybersecurity
V2EX - 技术
V2EX - 技术
S
Securelist
T
Threat Research - Cisco Blogs
Stack Overflow Blog
Stack Overflow Blog
TaoSecurity Blog
TaoSecurity Blog
云风的 BLOG
云风的 BLOG
Latest news
Latest news
人人都是产品经理
人人都是产品经理
L
LINUX DO - 最新话题
Application and Cybersecurity Blog
Application and Cybersecurity Blog
The Register - Security
The Register - Security
Webroot Blog
Webroot Blog
Simon Willison's Weblog
Simon Willison's Weblog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Security Blog
Microsoft Security Blog
AWS News Blog
AWS News Blog
C
Cybersecurity and Infrastructure Security Agency CISA
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
小众软件
小众软件
T
Tailwind CSS Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
宝玉的分享
宝玉的分享
O
OpenAI News

博客园 - 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();

        }

    }