By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,739 Members | 1,506 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,739 IT Pros & Developers. It's quick & easy.

How to show GridView bound to empty data source? (2.0)

P: n/a
Helo All,

The problem: GridView control does not render at all (header/footer) when
the data source is empty.
I have seen a similar question posted already, but I just can not believe
there is no simple solution.
I do not believe ASP.Net team took this, sort of, innovative approach and
left no way out.
Could anybody advise?

Thank you,
Tomasz
Nov 30 '06 #1
Share this Question
Share on Google+
13 Replies


P: n/a
"Tomasz Jastrzebski" <oe****@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Could anybody advise?
1) Launch your internet browser (e.g. IE, FireFox, Netcape, Opera etc)

2) Navigate to http://www.google.com

3) Enter the text below in the box:

GridView DataSource empty

4) Hit the button
Nov 30 '06 #2

P: n/a
Yeah, I think I have forgotten to to emphasize the word SIMPLE.
T
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:eE**************@TK2MSFTNGP06.phx.gbl...
"Tomasz Jastrzebski" <oe****@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>Could anybody advise?

1) Launch your internet browser (e.g. IE, FireFox, Netcape, Opera etc)

2) Navigate to http://www.google.com

3) Enter the text below in the box:

GridView DataSource empty

4) Hit the button

Nov 30 '06 #3

P: n/a
Perhaps the emptydatatext property of gridview would be simple enough
http://msdn2.microsoft.com/en-us/lib...ydatatext.aspx

--
Regards

John Timney (MVP)
VISIT MY WEBSITE:
http://www.johntimney.com
http://www.johntimney.com/blog
"Tomasz Jastrzebski" <oe****@nospam.nospamwrote in message
news:eW**************@TK2MSFTNGP02.phx.gbl...
Yeah, I think I have forgotten to to emphasize the word SIMPLE.
T
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:eE**************@TK2MSFTNGP06.phx.gbl...
>"Tomasz Jastrzebski" <oe****@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>>Could anybody advise?

1) Launch your internet browser (e.g. IE, FireFox, Netcape, Opera etc)

2) Navigate to http://www.google.com

3) Enter the text below in the box:

GridView DataSource empty

4) Hit the button


Nov 30 '06 #4

P: n/a
Simple - yes, helpful - I do not know. Setting this property does not seem
to cause header/footer to render when data source is empty. Am I missing
something?

Thanks,
Tomasz

"John Timney (MVP)" <x_****@timney.eclipse.co.ukwrote in message
news:Ad******************************@eclipse.net. uk...
Perhaps the emptydatatext property of gridview would be simple enough
http://msdn2.microsoft.com/en-us/lib...ydatatext.aspx

--
Regards

John Timney (MVP)
VISIT MY WEBSITE:
http://www.johntimney.com
http://www.johntimney.com/blog
"Tomasz Jastrzebski" <oe****@nospam.nospamwrote in message
news:eW**************@TK2MSFTNGP02.phx.gbl...
>Yeah, I think I have forgotten to to emphasize the word SIMPLE.
T
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:eE**************@TK2MSFTNGP06.phx.gbl...
>>"Tomasz Jastrzebski" <oe****@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl.. .

Could anybody advise?

1) Launch your internet browser (e.g. IE, FireFox, Netcape, Opera etc)

2) Navigate to http://www.google.com

3) Enter the text below in the box:

GridView DataSource empty

4) Hit the button



Nov 30 '06 #5

P: n/a
"John Timney (MVP)" <x_****@timney.eclipse.co.ukwrote in message
news:Ad******************************@eclipse.net. uk...
Perhaps the emptydatatext property of gridview would be simple enough
That's certainly the way I do it... :-)
Dec 1 '06 #6

P: n/a
AG
Apparently, MS doesn't consider this an issue and does not intend to change
it.
I submitted it to feedback and this is the result.
http://connect.microsoft.com/VisualS...dbackID=228384

While I haven't used it in production as yet, I am currently building a site
using the following, with a few tweaks.
http://www.codeproject.com/useritems...nsert_line.asp
If you want to be able to insert data, it works fine, except for one typo I
found.
If you just want to display header and footer without the insert, I think
you can easily modify it to do that.

The line:
public event GridViewUpdatedEventHandler RowInserting {
shoule be:
public event GridViewUpdateEventHandler RowInserting {

I also made a slight change to better handle utilizing template columns for
the command columns.

--

AG
Email: discuss at adhdata dot com

"Tomasz Jastrzebski" <oe****@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Helo All,

The problem: GridView control does not render at all (header/footer) when
the data source is empty.
I have seen a similar question posted already, but I just can not believe
there is no simple solution.
I do not believe ASP.Net team took this, sort of, innovative approach and
left no way out.
Could anybody advise?

Thank you,
Tomasz

Dec 1 '06 #7

P: n/a
Well, I should have guessed. I think it's my frustration. So good it's
almost Friday.
T

"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
"John Timney (MVP)" <x_****@timney.eclipse.co.ukwrote in message
news:Ad******************************@eclipse.net. uk...
>Perhaps the emptydatatext property of gridview would be simple enough

That's certainly the way I do it... :-)

Dec 1 '06 #8

P: n/a
Hi Tomasz,

You could use GridView's EmptyDataTemplate to display a message to user
that the GridView doesn't have any data available:

<EmptyDataTemplate>
There is no data.
</EmptyDataTemplate>
However, it will not show the header or footer. As a workaround, you could
use following class:

#10,000 Monkeys - Harnessing The Power of Typing Monkeys : Displaying
GridView When No Data Exists
http://blogs.claritycon.com/blogs/ke...02/28/247.aspx
You could use this class instead of GridView where is needed; or use
following config to automatically replace all GridView with EmptyGridView
without changing your existing WebForms:

<system.web>
<pages>
<tagMapping>
<!-- assume you added EmptyGridView to App_Code folder within namespace
"myns" -->
<add tagType="System.Web.UI.WebControls.GridView"
mappedTagType="myns.EmptyGridView,App_Code"/>
</tagMapping>
</pages>
</system.web>
Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Dec 1 '06 #9

P: n/a
If its not appropriate, you could probably just check the recordcount of the
datatable before you bind, and if its zero bind to a manually created
datatable containing a single record of spaces. That will render your
header and footer.

--
Regards

John Timney (MVP)
VISIT MY WEBSITE:
http://www.johntimney.com
http://www.johntimney.com/blog
"thomas" <th****@thomas.comwrote in message
news:eY**************@TK2MSFTNGP04.phx.gbl...
Well, I should have guessed. I think it's my frustration. So good it's
almost Friday.
T

"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>"John Timney (MVP)" <x_****@timney.eclipse.co.ukwrote in message
news:Ad******************************@eclipse.net .uk...
>>Perhaps the emptydatatext property of gridview would be simple enough

That's certainly the way I do it... :-)


Dec 1 '06 #10

P: n/a
Well, I know it will do the trick. I am currently doing some research before
we start coding a medium-sized project, so I want to make sure I have a
solution we can use consistently across the project, stay in compliance with
corporate usability standards etc.
That's why I am rather disapointed by this, so nice looking at MS held
presentations control.
Thanks,
Tomasz
"John Timney (MVP)" <x_****@timney.eclipse.co.ukwrote in message
news:IO******************************@eclipse.net. uk...
If its not appropriate, you could probably just check the recordcount of
the datatable before you bind, and if its zero bind to a manually created
datatable containing a single record of spaces. That will render your
header and footer.

--
Regards

John Timney (MVP)
VISIT MY WEBSITE:
http://www.johntimney.com
http://www.johntimney.com/blog
"thomas" <th****@thomas.comwrote in message
news:eY**************@TK2MSFTNGP04.phx.gbl...
>Well, I should have guessed. I think it's my frustration. So good it's
almost Friday.
T

"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>>"John Timney (MVP)" <x_****@timney.eclipse.co.ukwrote in message
news:Ad******************************@eclipse.ne t.uk...

Perhaps the emptydatatext property of gridview would be simple enough

That's certainly the way I do it... :-)



Dec 1 '06 #11

P: n/a
Thank you Walter. I am going to take this approach.
I see, however, that this EmptyGridView works only when GridView is bound to
a DataSourceControl object. When bound to a DataTable Columns collection
does not get populated. But I am thinkig of writing my DataSourceControl
anyway, which I could use with TableAdpters. I know that ObjectDataSource
can be used if combined with "direct methods" but there are some problems
and limitations. E.g. there is no good way of implementing error logging
which is a must.

Tomasz

"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:8G**************@TK2MSFTNGHUB02.phx.gbl...
Hi Tomasz,

You could use GridView's EmptyDataTemplate to display a message to user
that the GridView doesn't have any data available:

<EmptyDataTemplate>
There is no data.
</EmptyDataTemplate>
However, it will not show the header or footer. As a workaround, you could
use following class:

#10,000 Monkeys - Harnessing The Power of Typing Monkeys : Displaying
GridView When No Data Exists
http://blogs.claritycon.com/blogs/ke...02/28/247.aspx
You could use this class instead of GridView where is needed; or use
following config to automatically replace all GridView with EmptyGridView
without changing your existing WebForms:

<system.web>
<pages>
<tagMapping>
<!-- assume you added EmptyGridView to App_Code folder within namespace
"myns" -->
<add tagType="System.Web.UI.WebControls.GridView"
mappedTagType="myns.EmptyGridView,App_Code"/>
</tagMapping>
</pages>
</system.web>
Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your
reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Dec 1 '06 #12

P: n/a
Hi Tomasz,

You're right that the EmptyGridView only works when the GridView is bound
to a DataSourceControl. It's because it only overrides
CreateChildControls() method which I believe only gets called when bound to
a DataSourceControl.

Anyway, since you're going to create your own DataSourceControl, I think it
should be fine. Please feel free to let me know if there's anything I can
help.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Dec 4 '06 #13

P: n/a

Hi,

I have built and application with several GridViews which cannot be
rewritten since we are going live shortly. I would however like to
implement the EmptyGridView class. Can it be done without using
DataSourceControl?

Thanks,
co
--
neostile
------------------------------------------------------------------------
neostile's Profile: http://www.xpertgurus.com/member.php?userid=83
View this thread: http://www.xpertgurus.com/showthread.php?t=155078

Jan 19 '07 #14

This discussion thread is closed

Replies have been disabled for this discussion.