Design:
<asp:TemplateField HeaderText="Total Pcs">
<ItemTemplate>
<asp:Label ID="lbltotpcs"
runat="server" Text='<%# Bind("totpcs") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
Total
: <asp:Label ID="lbltotqty"
runat="server"
Text="Label"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
int totqty=0;
protected void
gvCrate_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label totpcs = (Label)e.Row.FindControl("lbltotpcs");
totqty = totqty + (Convert.ToInt32(totpcs.Text));
}
if (e.Row.RowType == DataControlRowType.Footer)
{
((Label)e.Row.FindControl("lbltotqty")).Text = totqty.ToString();
TxtTotalpcs.Value = totqty.ToString();
}
}
NOTE:
Enable "ShowFooter" as True in Gridview's property.