如何检查一个空的GridView [英] How to check for an Empty Gridview
本文介绍了如何检查一个空的GridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个ASP.NET 2.0(C#)Web应用程序,并在其中我有一个GridView,从Oracle数据库获取数据。
I have an ASP.NET 2.0 (C#) web app, and in it I have a gridview that gets its data from an oracle database.
我想知道如何检查,如果在GridView是空的,而做一些事情。
I want to know how to check if the gridview is empty, and the do something.
我已经尝试:
if(GridView.Rows.Count == 0)
{
// Do Something
}
,但它不工作...
but it doesn't work...
任何想法?
感谢您。
推荐答案
您code的应的工作。但只有在GridView.DataBind()被调用。一般来说,我不检查它的自我GridView控件,但网格视图的数据源。
Your code should work. But only after GridView.DataBind() has been called. Generally I don't check the GridView it's self, but the datasource of the grid view.
DataTable data = DAL.getdata();
if (data.Rows.Count == 0)
{
ShowEmptyData();
}
else
{
Grid.DataSource = dt;
Grid.DataBind();
}
这篇关于如何检查一个空的GridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文