Gridview Footer Help



I reviewed a couple of tutorials that show how to display totals in
the footer of a gridview. My footer shows up blank. Can someone help
me. The code is as follows:

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://">

<script runat="server">
Dim weighttotal As Decimal = 0
'Dim quantityTotal As Integer = 0
Sub detailsGridView_RowDataBound(ByVal sender As Object, _
ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
' add the UnitPrice and QuantityTotal to the running total
weighttotal +=
Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, _
ElseIf e.Row.RowType = DataControlRowType.Footer Then
e.Row.Cells(1).Text = "Totals:"
e.Row.Cells(2).Text = weighttotal.ToString()

e.Row.Cells(1).HorizontalAlign = HorizontalAlign.Right
e.Row.Cells(2).HorizontalAlign = HorizontalAlign.Right
e.Row.Font.Bold = True
End If
End Sub


<html xmlns="" >
<head runat="server">
<title>Untitled Page</title>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="ID"
DataSourceID="AccessDataSource1" Style="z-index: 100;
left: 88px; position: absolute;
top: 115px">
<asp:BoundField DataField="ID" HeaderText="ID"
InsertVisible="False" ReadOnly="True"
SortExpression="ID" />
<asp:BoundField DataField="Scale1" HeaderText="Scale1"
SortExpression="Scale1" />
<asp:BoundField DataField="Scale2" HeaderText="Scale2"
SortExpression="Scale2" />
<asp:BoundField DataField="Employee"
HeaderText="Employee" SortExpression="Employee" />
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
SelectCommand="SELECT * FROM [Scrap]"></




I think your problem is trying to access cells in the foota when there isn't
Put a table in the foota and use find control to access it
here is a example using a repeater

If e.Item.ItemType = ListItemType.Footer Then
Dim footaTab As Table = e.Item.FindControl("Table1")
Dim tc As TableCell = New TableCell
tc.Text = "5555"
End If

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question