Solved

Gridview Footer Totals Do Not Refresh

Posted on 2008-10-09
5
710 Views
Last Modified: 2010-04-21
I am running VB to count booleans that are true, then updating gridview footer quantities. Upon editing a row or doing a page refresh. Please review this code and see what I am doing wrong.
Imports Security_Check
Imports System.Data
 
 
Partial Class IT_DigitalCertificate
    Inherits System.Web.UI.Page
    Dim SM(10) As Integer
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim sss As String
        Dim pf As Boolean
        Dim i As Integer
        Dim j As Integer
        Dim k As Integer
 
        sss = User.Identity.Name.ToString
        sss = Mid(sss, InStr(sss, "\") + 1).ToLower
        pf = PASS("DigitalCertificateEDITS", sss)
 
        If pf = False Then
            GridView1.Columns(0).Visible = False
            DetailsView1.Visible = False
        End If
        If Not Page.IsPostBack Then
            UPDATE_COUNT()
        End If
    End Sub
 
    Public Sub UPDATE_COUNT()
        Dim arg As DataSourceSelectArguments
        arg = New DataSourceSelectArguments
        Dim view As System.Data.DataView = CType(SqlDataSource1.Select(arg), DataView)
 
        view.RowFilter = "QSE='True'"
        SM(1) = view.ToTable().Rows.Count
        view.RowFilter = "TDSP='True'"
        SM(2) = view.ToTable().Rows.Count
        view.RowFilter = "LSE='True'"
        SM(3) = view.ToTable().Rows.Count
        view.RowFilter = "RES='True'"
        SM(4) = view.ToTable().Rows.Count
        view.RowFilter = "TMPA='True'"
        SM(5) = view.ToTable().Rows.Count
 
        For k = 1 To 5
            GridView1.FooterRow.Cells(k + 3).Text = SM(k).ToString
        Next
        GridView1.FooterRow.Cells(0).Text = "Totals"
    End Sub
End Class
'==============================================
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="DigitalCertificate.aspx.vb" Inherits="IT_DigitalCertificate" title="Digital Certificates Administration" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
 
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:IntranetConnectionString %>" 
        DeleteCommand="DELETE FROM [DigitalCertificates] WHERE [id] = @id" 
        InsertCommand="INSERT INTO [DigitalCertificates] ([LastName], [FirstName], [QSE], [TDSP], [LSE], [RES], [TMPA], [EmployeeID], [ExpirationDate]) VALUES (@LastName, @FirstName, @QSE, @TDSP, @LSE, @RES, @TMPA, @EmployeeID, @ExpirationDate)" 
        SelectCommand="SELECT * FROM [DigitalCertificates] ORDER BY [LastName]" 
        UpdateCommand="UPDATE [DigitalCertificates] SET [LastName] = @LastName, [FirstName] = @FirstName, [QSE] = @QSE, [TDSP] = @TDSP, [LSE] = @LSE, [RES] = @RES, [TMPA] = @TMPA, [EmployeeID] = @EmployeeID, [ExpirationDate] = @ExpirationDate WHERE [id] = @id">
        <DeleteParameters>
            <asp:Parameter Name="id" Type="Byte" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="LastName" Type="String" />
            <asp:Parameter Name="FirstName" Type="String" />
            <asp:Parameter Name="QSE" Type="Boolean" />
            <asp:Parameter Name="TDSP" Type="Boolean" />
            <asp:Parameter Name="LSE" Type="Boolean" />
            <asp:Parameter Name="RES" Type="Boolean" />
            <asp:Parameter Name="TMPA" Type="Boolean" />
            <asp:Parameter Name="EmployeeID" Type="String" />
            <asp:Parameter Name="ExpirationDate" Type="DateTime" />
        </InsertParameters>
    </asp:SqlDataSource>
 
        <ContentTemplate>
            <asp:Table ID="Table1" runat="server" Width="675px">
            <asp:TableHeaderRow >
            <asp:TableCell><asp:Label ID="Label1" runat="server" Text="DIGITAL CERTIFICATES" Font-Size="XX-Large" ForeColor="Yellow"></asp:Label></asp:TableCell>
            </asp:TableHeaderRow>
    </asp:Table>
            <asp:GridView ID="GridView1" runat="server"
    AutoGenerateColumns="False" BackColor="White" BorderColor="#DEDFDE" 
    BorderStyle="None" BorderWidth="1px" CellPadding="4" DataKeyNames="id" 
    DataSourceID="SqlDataSource1" ForeColor="Black" GridLines="Vertical" 
    ShowFooter="True" Font-Size="Small" Font-Bold="True">
                <FooterStyle BackColor="#CCCC99" />
                <RowStyle BackColor="#F7F7DE" />
                <Columns>
                    <asp:CommandField ShowDeleteButton="True" 
                ShowEditButton="True" />
                    <asp:BoundField DataField="id" HeaderText="id" 
                ReadOnly="True" SortExpression="id" />
                    <asp:BoundField DataField="LastName" 
                HeaderText="LastName" SortExpression="LastName" />
                    <asp:BoundField DataField="FirstName" 
                HeaderText="FirstName" SortExpression="FirstName" />
                    <asp:CheckBoxField DataField="QSE" HeaderText="QSE" 
                SortExpression="QSE" />
                    <asp:CheckBoxField DataField="TDSP" HeaderText="TDSP" 
                SortExpression="TDSP" />
                    <asp:CheckBoxField DataField="LSE" HeaderText="LSE" 
                SortExpression="LSE" />
                    <asp:CheckBoxField DataField="RES" HeaderText="RES" 
                SortExpression="RES" />
                    <asp:CheckBoxField DataField="TMPA" HeaderText="TMPA" 
                SortExpression="TMPA" />
                    <asp:BoundField DataField="EmployeeID" 
                HeaderText="EmployeeID" SortExpression="EmployeeID" />
                    <asp:BoundField DataField="ExpirationDate" 
                HeaderText="ExpirationDate" SortExpression="ExpirationDate" />
                </Columns>
                <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
                <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
                <AlternatingRowStyle BackColor="White" />
            </asp:GridView>
        <br />
    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" OnItemInserted="UPDATE_COUNT"  
        BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" 
        CellPadding="3" DataKeyNames="id" DataSourceID="SqlDataSource1" 
        DefaultMode="Insert" GridLines="Horizontal" Height="50px" Width="125px" 
        Font-Size="X-Small">
        <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
        <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
        <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
        <Fields>
            <asp:BoundField DataField="id" HeaderText="id" ReadOnly="True" 
                SortExpression="id" Visible="False" />
            <asp:BoundField DataField="LastName" HeaderText="LastName" 
                SortExpression="LastName" />
            <asp:BoundField DataField="FirstName" HeaderText="FirstName" 
                SortExpression="FirstName" />
            <asp:CheckBoxField DataField="QSE" HeaderText="QSE" SortExpression="QSE" />
            <asp:CheckBoxField DataField="TDSP" HeaderText="TDSP" SortExpression="TDSP" />
            <asp:CheckBoxField DataField="LSE" HeaderText="LSE" SortExpression="LSE" />
            <asp:CheckBoxField DataField="RES" HeaderText="RES" SortExpression="RES" />
            <asp:CheckBoxField DataField="TMPA" HeaderText="TMPA" SortExpression="TMPA" />
            <asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" 
                SortExpression="EmployeeID" />
            <asp:BoundField DataField="ExpirationDate" HeaderText="ExpirationDate" 
                SortExpression="ExpirationDate" />
            <asp:CommandField ShowInsertButton="True" />
        </Fields>
        <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
        <EditRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
        <AlternatingRowStyle BackColor="#F7F7F7" />
    </asp:DetailsView>
        </ContentTemplate>
</asp:Content>

Open in new window

0
Comment
Question by:wrwiii12
  • 2
  • 2
5 Comments
 
LVL 20

Expert Comment

by:informaniac
ID: 22684282
Remove this

If Not Page.IsPostBack Then
            UPDATE_COUNT()
        End If

and write

UPDATE_COUNT()
0
 
LVL 4

Author Comment

by:wrwiii12
ID: 22684387
It didn't work. If I delete a row, edit a row, or do a page refresh, the totals go away.
0
 
LVL 20

Expert Comment

by:informaniac
ID: 22684438
The problem is that on page postback, first the page load event is gettin fired, where the update_count() method is fired and after that the updation of the data in d/b is occuring, which does not update the footer row
0
 
LVL 22

Accepted Solution

by:
prairiedog earned 500 total points
ID: 22689086
After the update or delete, first you need to rebind your GridView, then call UPDATE_COUNT right after rebinding GridView.
0
 
LVL 4

Author Closing Comment

by:wrwiii12
ID: 31504904
i had to add ondatabound to my html code for the gridview to call the updatefooter routine.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSRS ReportViewer report timeout 7 122
Remove greater than sign 3 68
Angular JS Route 3 68
Displaying a web form as a modal popup dialog box. 4 30
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

785 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