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

Discussion in 'ASP .Net' started by Tomasz Jastrzebski, Nov 30, 2006.

  1. 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
     
    Tomasz Jastrzebski, Nov 30, 2006
    #1
    1. Advertising

  2. Tomasz Jastrzebski

    Mark Rae Guest

    "Tomasz Jastrzebski" <> wrote in message
    news:%...

    > 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
     
    Mark Rae, Nov 30, 2006
    #2
    1. Advertising

  3. Yeah, I think I have forgotten to to emphasize the word SIMPLE.
    T


    "Mark Rae" <> wrote in message
    news:...
    > "Tomasz Jastrzebski" <> wrote in message
    > news:%...
    >
    >> 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
    >
     
    Tomasz Jastrzebski, Nov 30, 2006
    #3
  4. Perhaps the emptydatatext property of gridview would be simple enough
    http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.emptydatatext.aspx

    --
    Regards

    John Timney (MVP)
    VISIT MY WEBSITE:
    http://www.johntimney.com
    http://www.johntimney.com/blog


    "Tomasz Jastrzebski" <> wrote in message
    news:...
    > Yeah, I think I have forgotten to to emphasize the word SIMPLE.
    > T
    >
    >
    > "Mark Rae" <> wrote in message
    > news:...
    >> "Tomasz Jastrzebski" <> wrote in message
    >> news:%...
    >>
    >>> 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
    >>

    >
    >
     
    John Timney \(MVP\), Nov 30, 2006
    #4
  5. 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)" <> wrote in message
    news:...
    > Perhaps the emptydatatext property of gridview would be simple enough
    > http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.emptydatatext.aspx
    >
    > --
    > Regards
    >
    > John Timney (MVP)
    > VISIT MY WEBSITE:
    > http://www.johntimney.com
    > http://www.johntimney.com/blog
    >
    >
    > "Tomasz Jastrzebski" <> wrote in message
    > news:...
    >> Yeah, I think I have forgotten to to emphasize the word SIMPLE.
    >> T
    >>
    >>
    >> "Mark Rae" <> wrote in message
    >> news:...
    >>> "Tomasz Jastrzebski" <> wrote in message
    >>> news:%...
    >>>
    >>>> 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
    >>>

    >>
    >>

    >
    >
     
    Tomasz Jastrzebski, Nov 30, 2006
    #5
  6. Tomasz Jastrzebski

    Mark Rae Guest

    "John Timney (MVP)" <> wrote in message
    news:...

    > Perhaps the emptydatatext property of gridview would be simple enough


    That's certainly the way I do it... :)
     
    Mark Rae, Dec 1, 2006
    #6
  7. Tomasz Jastrzebski

    AG Guest

    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.

    --

    AG
    Email: discuss at adhdata dot com



    "Tomasz Jastrzebski" <> wrote in message
    news:%...
    > 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
    >
     
    AG, Dec 1, 2006
    #7
  8. Tomasz Jastrzebski

    thomas Guest

    Well, I should have guessed. I think it's my frustration. So good it's
    almost Friday.
    T

    "Mark Rae" <> wrote in message
    news:%...
    > "John Timney (MVP)" <> wrote in message
    > news:...
    >
    >> Perhaps the emptydatatext property of gridview would be simple enough

    >
    > That's certainly the way I do it... :)
    >
     
    thomas, Dec 1, 2006
    #8
  9. 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 (, 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.
     
    Walter Wang [MSFT], Dec 1, 2006
    #9
  10. 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" <> wrote in message
    news:...
    > Well, I should have guessed. I think it's my frustration. So good it's
    > almost Friday.
    > T
    >
    > "Mark Rae" <> wrote in message
    > news:%...
    >> "John Timney (MVP)" <> wrote in message
    >> news:...
    >>
    >>> Perhaps the emptydatatext property of gridview would be simple enough

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

    >
    >
     
    John Timney \(MVP\), Dec 1, 2006
    #10
  11. 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)" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:...
    >> Well, I should have guessed. I think it's my frustration. So good it's
    >> almost Friday.
    >> T
    >>
    >> "Mark Rae" <> wrote in message
    >> news:%...
    >>> "John Timney (MVP)" <> wrote in message
    >>> news:...
    >>>
    >>>> Perhaps the emptydatatext property of gridview would be simple enough
    >>>
    >>> That's certainly the way I do it... :)
    >>>

    >>
    >>

    >
    >
     
    Tomasz Jastrzebski, Dec 1, 2006
    #11
  12. 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]" <> wrote in message
    news:...
    > 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 (, 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.
    >
     
    Tomasz Jastrzebski, Dec 1, 2006
    #12
  13. 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 (, 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.
     
    Walter Wang [MSFT], Dec 4, 2006
    #13
  14. Tomasz Jastrzebski

    neostile Guest

    neostile, Jan 19, 2007
    #14
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sunil panda

    Lower bound & Upper bound

    sunil panda, Dec 25, 2003, in forum: Java
    Replies:
    9
    Views:
    7,327
    thushara wijeratna
    Oct 7, 2008
  2. Rhiner Dan
    Replies:
    1
    Views:
    763
    Mike Wahler
    Mar 27, 2005
  3. Mario Krsnic
    Replies:
    0
    Views:
    392
    Mario Krsnic
    Jun 23, 2006
  4. Phillip Vong
    Replies:
    0
    Views:
    428
    Phillip Vong
    Jul 27, 2006
  5. Replies:
    1
    Views:
    915
    Munna
    Jul 6, 2008
Loading...

Share This Page