Hi,

I am new to web development, and have got myself stuck when trying to show totals in the footer of a gridview. I am building my grid from an oracle DB, and have the used the code below to generate my totals. By using debugs I can see that it is getting me the total as expected, however after looping through all the data rows it never seems to enter the elseif that check if the next row is the footer. Therefore it never shows the total in the grids footer at runtime.

Any ideas? Any help would be greatly appreciated. I have included my asp code and also the vb.net code used to fill the grid.

<td colspan="2">
                    <asp:GridView ID="GridView1" 
                        AutoGenerateColumns="false" DataKeyNames="category_code" 
                        runat="server" OnRowDataBound="GridView1_RowDataBound" OnRowUpdating = "GridView1_RowUpdating" 
                        OnRowEditing ="GridView1_RowEditing" OnRowCancelingEdit = "GridView1_CancelingEdit" ShowFooter="True">
                            <AlternatingRowStyle CssClass="alter_style" />
                            <RowStyle CssClass="alter_style" />
                            <HeaderStyle CssClass="loan_header"/>
                            <Columns>
                            <asp:TemplateField>
                            <ItemTemplate>
                                <a href="javascript:expandcollapse('div<%# Eval("category_code") %>', 'one');">
                                <img id="imgdiv<%# Eval("category_code") %>" alt="Click to show/hide Orders for Budget <%# Eval("category_code") %>"  width="9px" border="0" src="Images/plus.gif"/>
                                </a>
                            </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Code">
                            <ItemTemplate>
                                <asp:Label ID="lblCode" Text='<%# Eval("category_code") %>'  runat="server"></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:label ID="lblCategory_code" Text='<%# Eval("category_code") %>' Width ="70px" runat="server"></asp:label>
                            </EditItemTemplate>
                            </asp:TemplateField> 
                            <asp:TemplateField HeaderText="Description">
                            <ItemTemplate>
                                <asp:Label ID="lblDescription" Text='<%# Eval("description") %>'  runat="server"></asp:Label>
                            </ItemTemplate>
                            </asp:TemplateField> 
                            <asp:TemplateField HeaderText="Budget Amt">
                            <ItemTemplate>
                                <asp:Label ID="lblBudgetAmt" Text='<%# Eval("budget_amt") %>' Width ="70px" runat="server" ></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:textbox ID="txtBudgetAmt" Text='<%# Eval("budget_amt") %>' Width ="70px" runat="server"></asp:textbox>
                            </EditItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Pay Freq" >
                            <ItemTemplate>
                                <asp:Label ID="lblPayfreq" Text='<%# Eval("pay_freq") %>' Width ="70px" runat="server"></asp:Label>
                            </ItemTemplate>
                            <edititemTemplate>
                                <asp:DropDownList ID="ddPayFreq" runat="server" DataTextField="pay_freq" DataValueField ="pay_freq">
                                <asp:ListItem Text="Yearly" Value="Y" />
                                <asp:ListItem Text="monthly" value="M" />
                                <asp:ListItem Text="weekly" Value="W" />
                                </asp:DropDownList>
                            </edititemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField>
                            <editItemTemplate>
                                <asp:Label ID="lblbuap_no" Text='<%# Eval("buap_no") %>' Visible ="false" runat="server"></asp:Label>
                            </editItemTemplate>
                            </asp:TemplateField>
                            <asp:CommandField ShowEditButton="True" />
                            <asp:TemplateField>
			                <ItemTemplate>
			                    <tr>
                                    <td colspan="100%">
                                    <div id="div<%# Eval("category_code") %>" style="display:none;position:relative;left:15px;OVERFLOW: auto;WIDTH:100%" >
                                    <asp:GridView ID="GridView2" ...............





vb.net code

 Protected Sub GridView1_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
                priceTotal += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "budget_amt"))
                If e.Row.DataItem("budget_amt") = 0.0 Then
                    e.Row.Cells(3).Text = ""
                End If
            ElseIf e.Row.RowType = DataControlRowType.Footer Then
                e.Row.Cells(0).Text = "Totals:"
                ' for the Footer, display the running totals
                e.Row.Cells(1).Text = priceTotal.ToString("c")

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

where did u declare footer row in grid view

Hi,

I'm not sure I know what you mean? I thought by having ShowFooter set to true in the asp code this would simply enable the footer, thus allowing me to reference it. When I run the application a footer does appear at the bottom of the grid, however the totals fields i want to display dont show.

How do I declare the footer row for the grid?

Regards,

David.

if u want to declare footer row,u can do it by declaring footer row in grid view
by using footertemplate
<asp:TemplateField>
<FooterTemplate>

</FooterTemplate>
</asp:TemplateField>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.