Solved

Show Footer on GridView with empty records

Posted on 2011-03-09
3
657 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

21 Experts available now in Live!

Get 1:1 Help Now