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

  • Thread starter Thread starter Tomasz Jastrzebski
  • Start date Start date
T

Tomasz Jastrzebski

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
 
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
 
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/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=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/GridView_with_insert_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.
 
Well, I should have guessed. I think it's my frustration. So good it's
almost Friday.
T
 
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/kevin_marshall/archive/2006/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 ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
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
 
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
 
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 ([email protected], 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.
 
Back
Top