?
Solved

Show Footer on GridView with empty records

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

770 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