locked
How to display Gridview Header and Footer when sqldatasource returns no data? RRS feed

  • Question

  • User-1347875012 posted

    I am using sqldatasource to populate my GridView which contains a header and a footer. I use the footer to inser a new row in the database. The problem is: when the sqldatasource returns with no data in the database, the GridView is not displayed. Therefore, I have no way of inserting a new record under this condition.

    Can anyone show me how do I keep displaying the GridView with the header and footer even when the sqldatasource returns with no data?

    Thanks in advance.

    sg2000

     

    Tuesday, May 13, 2008 6:00 PM

Answers

  • User-156759649 posted

    good 'ol  chicken / egg cyndrome [:)]  Personally I would never put my add inside the grid. Now you know why.  The only option is to replace the sqlDataSource with a dataTable and maintain a dummy record around to populate the grid. Or logic that create the dummy record under those circumstances. 

    Another solution is to place the add button outside the grid.  Other than this...

    Interesting to note that the grid has no built in functionality for insert at least not button command. It has to be hacked in. Ever wonder why? 

    Sorry,

     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 13, 2008 6:20 PM

All replies

  • User-156759649 posted

    good 'ol  chicken / egg cyndrome [:)]  Personally I would never put my add inside the grid. Now you know why.  The only option is to replace the sqlDataSource with a dataTable and maintain a dummy record around to populate the grid. Or logic that create the dummy record under those circumstances. 

    Another solution is to place the add button outside the grid.  Other than this...

    Interesting to note that the grid has no built in functionality for insert at least not button command. It has to be hacked in. Ever wonder why? 

    Sorry,

     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 13, 2008 6:20 PM
  • User-1347875012 posted

    aamador:

    Thanks for the quick response. Yes, I agree that using GridView to add a record is pain in the neck, and may be not be doable with sqldatasource. However, sqldatasource is so convinient to handle paging and sorting, and using the footer to add data is so natural and intuitive for the user (as the footer columns are lined up with the grid columns). Well, may be I will abandon this idea and use other method. Thanks.

    sg2000

     

     

    Tuesday, May 13, 2008 8:45 PM
  • User-31526489 posted

    I use the generic list to solve this issue and i publish this solution on my blog check it and if you have and question contact me or reply

    http://blog.waleedmohamed.net/2009/04/show-grid-view-header-and-footer-when.html

    Thursday, February 11, 2010 5:44 AM
  • User2115139740 posted

    Can anyone show me how do I keep displaying the GridView with the header and footer even when the sqldatasource returns with no data?


    Show Header and Footer when records are empty
    http://mattberseth.com/blog/2007/07/how_to_show_header_and_footer.html


    Thursday, February 11, 2010 5:51 AM
  • Thursday, August 15, 2013 10:17 AM