how to TOTAL & GRAND TOTAL in FOOTER in gridview


Default.aspx

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" GridLines="None"
            BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
            CellPadding="3" CellSpacing="2" onrowdatabound="GridView1_RowDataBound"  ShowFooter="True"
            AllowPaging="True" onpageindexchanging="GridView1_PageIndexChanging"
            PageSize="2" >
            <PagerSettings FirstPageText="First" />
            <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
        <Columns>



<asp:TemplateField>
        <ItemTemplate>
            <asp:HiddenField ID="HiddenField1" runat="server" Value='<%#Eval("id") %>' />
       </ItemTemplate>
        </asp:TemplateField>
       
        <asp:TemplateField HeaderText="Name">
        <ItemTemplate>
            <asp:Label ID="Label1" runat="server" style="text-transform:capitalize" Text='<%#Eval("name") %>'></asp:Label>
        </ItemTemplate>
           <FooterTemplate>
            <asp:Label ID="Label5" runat="server" Text="TOTAL ="></asp:Label>
        </FooterTemplate>
        </asp:TemplateField>
       
        <asp:TemplateField HeaderText="Description">
        <ItemTemplate>
            <asp:Label ID="Label2" runat="server" Text='<%#Eval("description") %>'></asp:Label>
        </ItemTemplate>
       <FooterTemplate>
            <asp:Label ID="lbltot" runat="server"></asp:Label>
        </FooterTemplate>
        </asp:TemplateField>
       
        <asp:TemplateField HeaderText="Grand Total">
        <ItemTemplate>
            <asp:Label ID="Label3" runat="server" Text='<%#Eval("total") %>'></asp:Label>
        </ItemTemplate>
      <FooterTemplate>
            <asp:Label ID="Label9" runat="server" Text="GrandTotal ="></asp:Label>
        </FooterTemplate>
        </asp:TemplateField>
       
        <asp:TemplateField HeaderText="Edit/Delete">
        <ItemTemplate>
            <asp:LinkButton ID="LinkButton1" runat="server" OnClick="editDetail" >Edit</asp:LinkButton>
            <asp:LinkButton ID="LinkButton2" runat="server" OnClick="LinkButton2_Click">Delete</asp:LinkButton>
        </ItemTemplate>
        <FooterTemplate>
        <asp:Label ID="lblgt" runat="server"></asp:Label>
        </FooterTemplate>
        </asp:TemplateField>


</Columns>
            <FooterStyle BackColor="#A55129" ForeColor="White" Font-Bold="True" />
            <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
        </asp:GridView>



Default.aspx.CS

int gt = 0;
int z ;

if (IsPostBack)
        {
            SqlDataAdapter da = new SqlDataAdapter("SELECT SUM(total) FROM v_rate2 ", cn);
            da.Fill(dt1);
            z = int.Parse(dt1.Rows[0][0].ToString());
        }


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            con.Open()

            Label total = (Label)e.Row.FindControl("lbltotal");

            int tot = Convert.ToInt32(total.Text);
            gt += tot;

       }
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            Label total = (Label)e.Row.FindControl("footer_total");
            total.Text = gt.ToString();
            Label ggtt = (Label)e.Row.FindControl("lblgt");
            ggtt.Text = z.ToString();
           
        }
       
    }