check for if a gridview is empty

G

Guest

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
--
(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
 
G

Guest

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
--

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.emptydatatext.aspx
 
G

Guest

No i did not that is why i asked the question. Thank you for this answer it
is very much appreciated.


--
(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
 
G

Guest

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;
}
 
G

Guest

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!
--
(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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top