Solved

Show Footer on GridView with empty records

Posted on 2011-03-09
3
668 Views
Last Modified: 2012-06-27
I've setup a gridview with extra fields in the footer to allow inserts.  My problem is, that if the sqldatasourcr contains no records the gridview does not display and thus the footer does not, so I can't insert any new records.
What do I do?

0
Comment
Question by:TonyReba
  • 2
3 Comments
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 500 total points
ID: 35089613
A couple of ways either define an emptydatatemplate :

<asp:gridview id="CustomersGridView"  
        datasourceid="CustomersSqlDataSource"  
        autogeneratecolumns="true" 
        runat="server"> 
 
        <emptydatarowstyle backcolor="LightBlue" 
          forecolor="Red"/> 
 
        <emptydatatemplate> 
 
          <asp:image id="NoDataImage" 
            imageurl="~/images/Image.jpg" 
            alternatetext="No Image"  
            runat="server"/> 
 
            No Data Found.   
 
        </emptydatatemplate>  
 
      </asp:gridview> 

Open in new window


or you can put in a dummy row if nothing is returned and then hide it:

    Protected Sub Page_PreRenderComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRenderComplete 
        If gvSites.Rows.Count = 0 Then 
            AddDummySiteRow() 
        End If 
    End Sub

    ''' <summary> 
    ''' Create a dummy hidden row so that the title bar columns remain 
    ''' </summary> 
    ''' <remarks></remarks> 
    Private Sub AddDummySiteRow() 
        Try 
            Dim lstDummy As New Collections.Generic.List(Of JEMSConfiguration.BLL.Site) 
            lstDummy.Add(New JEMSConfiguration.BLL.Site) 
            gvSites.DataSourceID = "" 
            gvSites.DataSource = lstDummy 
            gvSites.DataBind() 
 
            With gvSites.Rows(0) 
                ' hide the delete and edit buttons 
                .Cells(0).Controls(1).Visible = False 
                .Cells(0).Controls(3).Visible = False 
 
                ' hide the labels displaying the dummy data 
                .Cells(1).Controls(1).Visible = False 
                .Cells(2).Controls(1).Visible = False 
                .Cells(3).Controls(1).Visible = False 
                .Cells(4).Controls(1).Visible = False 
            End With 
 
        Catch ex As Exception 
            Throw 
        End Try 
    End Sub

Open in new window

0
 
LVL 9

Author Comment

by:TonyReba
ID: 35089650
Well  , the requirement as I mentioned, is that, I should be able to use the Insert button and show the footer template, so i can add my first record, does it makes sense?

I actually tried pasting the html code generated from the page, but could not make the insert button work since, it looks for the
.FooterRow.FindControl("txtNT1Census")).Text;

0
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 35089691
Yes and if you use one of the techniques in my last post the footer will be shown.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now