Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

check for if a gridview is empty

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
WebBuilder451 - 29 Aug 2007 22:00 GMT
What is a good way to check for a gridview or a datasource not having any rows?
If my gridview does not have any rows i want to display a message saying the
recordset is empty.

I'm doing it now by setting the message visible = true on page load
and set it to false on

if (e.Row.RowType == DataControlRowType.DataRow)
   this.Label1.Visible = false;

Meaning it get s set to false on each row. I'd like a better way.

Thanks
KES
Signature

(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes

Alexey Smirnov - 30 Aug 2007 00:09 GMT
On Aug 29, 11:00 pm, WebBuilder451
<WebBuilder...@discussions.microsoft.com> wrote:
> What is a good way to check for a gridview or a datasource not having any rows?
> If my gridview does not have any rows i want to display a message saying the
[quoted text clipped - 11 lines]
> KES
> --

Do you know that there is the EmptyDataText Property that can be used
to show such message?
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.empt
ydatatext.aspx

WebBuilder451 - 30 Aug 2007 13:48 GMT
No i did not that is why i asked the question. Thank you for this answer it
is very much appreciated.

Signature

(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes

> On Aug 29, 11:00 pm, WebBuilder451
> <WebBuilder...@discussions.microsoft.com> wrote:
[quoted text clipped - 17 lines]
> to show such message?
> http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.empt
ydatatext.aspx
Alexey Smirnov - 30 Aug 2007 13:57 GMT
On Aug 30, 2:48 pm, WebBuilder451
<WebBuilder...@discussions.microsoft.com> wrote:
> No i did not that is why i asked the question. Thank you for this answer it
> is very much appreciated.

okay, and if you still want to use code-behind you can use Rows.Count
property

...
GridView1.DataBind();
if (GridView1.Rows.Count == 0) {
Label1.Text = "No records found";
Label1.Visible = true;
}
WebBuilder451 - 30 Aug 2007 14:52 GMT
i was adding header rows on row data bound or row created and this was always
throwing the count off.

I did not see that property for empty text. Again This was an obvious, big
still a big help!
Signature

(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes

> On Aug 30, 2:48 pm, WebBuilder451
> <WebBuilder...@discussions.microsoft.com> wrote:
[quoted text clipped - 10 lines]
> Label1.Visible = true;
> }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.