[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Show Footer on GridView with empty records

Posted on 2011-03-09
3
Medium Priority
?
689 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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 course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

650 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