473,503 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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://
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>
Jun 27 '08 #1
1 1654
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



"Michael" <bg********@gmail.comwrote in message
news:89**********************************@59g2000h sb.googlegroups.com...
>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>
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
9331
by: Miguel Dias Moura | last post by:
Hello, I have a GridView in my page which is created in runtime. It works fine. My page has 2 Asp Buttons: - The HIDE button makes GridView.Visible = False; - The SHOW button makes...
0
1434
by: tfsmag | last post by:
I know how to do summary footers in a gridview... but when i try it in a paged gridview it puts a footer on every page of just the items on that page. Any suggestions on how to get it to work so...
2
2745
by: Flinky Wisty Pomm | last post by:
Hi all, I've got a really annoying problem that I need to fix sharpish. I've got a GridView derived control which has a templated header and footer. It works wonderfully on the first render but...
0
937
by: yossimotro | last post by:
Hi, I'm using a gridview in my project and its footer to add new records. The gridview is connected to an AccessDataSource which contains select, insert and delete commands. The problem...
0
1578
by: luvdairish | last post by:
Controls (in order on page) 1.)GridView - each row is a work order w/ a link for details in the last column 2.)DetailsView - when user clicks on link from above GridView, the details are shown...
0
7781
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I have to display total time in the footer of my gridview so I have a columnn a. I followed micrososft example to create the footer and display the total time and it is not...
0
1772
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I have a gridview. I calculated some values in the gridview for the footer of the gridview so basically I am adding all the values that are displayed in the gridview for each...
0
2650
by: gnewsgroup | last post by:
Well, I am trying to use the footer row of a GridView for insertion purpose. There are some articles about this, for example, the gridviewguy.com has an example, which always displays the footer...
3
9806
by: tshad | last post by:
I am building a GridView that is displaying some money values in 3 columns. I want to put the totals of each column in a label field (one for each column) in the footer. I was trying to figure...
0
7198
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7072
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7271
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5570
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4998
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.