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

Last post 05-13-2008 8:45 PM by sg2000. 2 replies.

Sort Posts:

  • How to display Gridview Header and Footer when sqldatasource returns no data?

    05-13-2008, 6:00 PM
    • Member
      359 point Member
    • sg2000
    • Member since 05-04-2003, 3:34 PM
    • Posts 154

    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

     

  • Re: How to display Gridview Header and Footer when sqldatasource returns no data?

    05-13-2008, 6:20 PM
    Answer
    • Contributor
      5,201 point Contributor
    • aamador
    • Member since 02-11-2008, 10:49 PM
    • Posts 1,107

    good 'ol  chicken / egg cyndrome Smile  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,

     

     

    I am not anti social, am just not user friendly
  • Re: How to display Gridview Header and Footer when sqldatasource returns no data?

    05-13-2008, 8:45 PM
    • Member
      359 point Member
    • sg2000
    • Member since 05-04-2003, 3:34 PM
    • Posts 154

    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

     

     

Page 1 of 1 (3 items)