Gridview Footer Sum of Column

<ItemTemplate>
<asp:Label ID=”lblADET” runat = “server” Text='<%# Eval(“QT_ADET”) %>’></asp:Label>
</ItemTemplate>
<FooterTemplate>

</FooterTemplate>
<ItemStyle Width=”100px” />
</asp:TemplateColumn>
<asp:BoundColumn DataField=”QT_ADET” HeaderText=”Adet” Visible=”false”>
<HeaderStyle HorizontalAlign=”Left” />
<ItemStyle HorizontalAlign=”Left” />
</asp:BoundColumn>

<asp:TemplateColumn HeaderText = “KgDesi”>
<ItemTemplate>
<asp:Label ID=”lblKGDESI” runat = “server” Text='<%# Eval(“QT_KG_DESI”) %>’></asp:Label>
</ItemTemplate>
<FooterTemplate>

</FooterTemplate>
<ItemStyle Width=”100px” />
</asp:TemplateColumn>
<asp:BoundColumn DataField=”QT_KG_DESI” HeaderText=”KgDesi” Visible =”false”>
<HeaderStyle HorizontalAlign=”Left” />
<ItemStyle HorizontalAlign=”Left” />
</asp:BoundColumn>

<asp:TemplateColumn HeaderText = “Birim Ücret”>
<ItemTemplate>
<asp:Label ID=”lblBIRIMUCRET” runat = “server” Text='<%# Eval(“BIRIM_UCRET”) %>’></asp:Label>
</ItemTemplate>
<FooterTemplate>

</FooterTemplate>
<ItemStyle Width=”100px” />
</asp:TemplateColumn>
<asp:BoundColumn DataField=”BIRIM_UCRET” HeaderText=”Birim Ücret” Visible=”false”>
<HeaderStyle HorizontalAlign=”Left” />
<ItemStyle HorizontalAlign=”Left” />
</asp:BoundColumn>

<asp:TemplateColumn HeaderText = “Toplam Tutar&lt;br/&gt;(KDV Hariç)”>
<ItemTemplate>
<asp:Label ID=”lblTOPLAMTUTAR” runat = “server” Text='<%# Eval(“PR_TOPLAM”) %>’></asp:Label>
</ItemTemplate>
<FooterTemplate>

</FooterTemplate>
<ItemStyle Width=”100px” />
</asp:TemplateColumn>

decimal pTutar = 0;
decimal pKgDesi = 0;
decimal pAdet = 0;
decimal pBirimUcret = 0;
protected void dgListe_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
decimal lblTOPLAMTUTAR = Convert.ToDecimal((e.Item.FindControl(“lblTOPLAMTUTAR”) as Label).Text);
decimal lblKGDESI = Convert.ToDecimal((e.Item.FindControl(“lblKGDESI”) as Label).Text);
decimal lblADET = Convert.ToDecimal((e.Item.FindControl(“lblADET”) as Label).Text);
decimal lblBIRIMUCRET = Convert.ToDecimal((e.Item.FindControl(“lblBIRIMUCRET”) as Label).Text);
pTutar += lblTOPLAMTUTAR;
pKgDesi += lblKGDESI;
pAdet += lblADET;
pBirimUcret += lblBIRIMUCRET;
}

//// FINALLY, SHOW THE RUNNING AND GRAND TOTAL ON EACH PAGE.
if (e.Item.ItemType == ListItemType.Footer)
{
// ToplamTutar
Label lblBIRIMUCRET = e.Item.FindControl(“flblBIRIMUCRET”) as Label;
lblBIRIMUCRET.Text = pBirimUcret.ToString();
lblBIRIMUCRET.Font.Bold = true;

// ToplamTutar
Label lblTOPLAMTUTAR = e.Item.FindControl(“flblTOPLAMTUTAR”) as Label;
lblTOPLAMTUTAR.Text = pTutar.ToString();
lblTOPLAMTUTAR.Font.Bold = true;

//ToplamDesi
Label lblKGDESI = e.Item.FindControl(“flblKGDESI”) as Label;
lblKGDESI.Text = pKgDesi.ToString();
lblKGDESI.Font.Bold = true;

//ToplamAdet
Label lblADET = e.Item.FindControl(“flblADET”) as Label;
lblADET.Text = pAdet.ToString();
lblADET.Font.Bold = true;

}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: