Gridview Footer Help

  • Thread starter Thread starter Michael
  • Start date Start date
M

Michael

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://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<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
variables
weighttotal +=
Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, _
"scale1"))
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


</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="ID"
showfooter=true
DataSourceID="AccessDataSource1" Style="z-index: 100;
left: 88px; position: absolute;
top: 115px">
<Columns>
<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" />
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/Spare_Parts_II_BCPC.mdb"
SelectCommand="SELECT * FROM [Scrap]"></
asp:AccessDataSource>

</div>
</form>
</body>
</html>
 
I think your problem is trying to access cells in the foota when there isn't
any.
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"
footaTab.Rows(0).Cells.Add(tc)
End If
 
Back
Top