Solved

Show Footer on GridView with empty records

Posted on 2011-03-09
3
675 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Broken .resx file generating errors 18 44
Access-Control-Allow-Origin 4 44
Using the .NET JSON Serializer to create a single string 6 57
Easiest intro into .NET CORE? 2 32
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 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