473,408 Members | 2,450 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

check for if a gridview is empty

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
Aug 29 '07 #1
4 29741
On Aug 29, 11:00 pm, WebBuilder451
<WebBuilder...@discussions.microsoft.comwrote:
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/lib...ydatatext.aspx

Aug 29 '07 #2
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
"Alexey Smirnov" wrote:
On Aug 29, 11:00 pm, WebBuilder451
<WebBuilder...@discussions.microsoft.comwrote:
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/lib...ydatatext.aspx

Aug 30 '07 #3
On Aug 30, 2:48 pm, WebBuilder451
<WebBuilder...@discussions.microsoft.comwrote:
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;
}

Aug 30 '07 #4
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
"Alexey Smirnov" wrote:
On Aug 30, 2:48 pm, WebBuilder451
<WebBuilder...@discussions.microsoft.comwrote:
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;
}

Aug 30 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Paul Telco | last post by:
Hello, I'm a new user designing a simple database to retrieve pre-prepared docunents for printing. I have five tables, a form to design the documents, a form to customise and retrieve the...
30
by: S. van Beek | last post by:
Dear reader A record set can be empty because the condition in the query delivers no records. Is there a VBA code to check the status of a record set, record set empty
1
by: Oleg Ogurok | last post by:
Hi all, I want to use RegularExpressionValidator to enforce non-empty integer format in a TextBox. However, the validator doesn't give the error when the textbox is empty. For example, if...
0
by: Krish | last post by:
Hello, I have GridView and after binding data i can see cells empty only (empty row is created), but i checked database there is data available. I just started using GridView, trying to learn...
5
by: Mark Olbert | last post by:
I ran into a situation this morning where the RowUpdating event of a GridView kept insisting there were no entries in either the OldValues or NewValues dictionaries. The GridView is bound to a...
4
by: whisher | last post by:
Hi. I'm taking my first steps on regex I set up this simple function to check if a form field is empty or with only space. var onlySpaceRegexp = /^\s*$/; function isEmpty(val) { if...
2
by: Mr. SweatyFinger | last post by:
how do i tell if i got back records (in code) thanks
7
by: lphang | last post by:
I am reading a simple text file that will contains three set of string values as follow: "1234567", "ABC123456", "" I have my codes as follow trying to check for an empty string, with the input...
2
by: Knoxy | last post by:
Hi guys, I'm using a gridview to do some inline editing. The data binds okay, its goes into edit mode and cancel okay. I'm using my own custom commandName, "save", and it picks this up okay. Don't...
3
by: akshalika | last post by:
I want regular expression which check for empty. pls help me.
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.