Sending a datagrid's column

K

keal75

Does anyone know how to sum a datagrid's column & display the total in the
footer of the datagrid.

Thanks
 
D

Davie James Paulino

I Hope this will help you!
'HTML Code
<asp:TemplateColumn HeaderText="NUMBER OF SHARES">
<HeaderStyle Width="2.5%"></HeaderStyle>
<ItemTemplate>
<%#
Format(databinder.eval(container.dataitem,"NoShares"),"#,##0;(#,##0)")
%>
</ItemTemplate>
<FooterStyle HorizontalAlign="Center"></FooterStyle>
<FooterTemplate>
<asp:Label ID="lblTotal" Runat="server"></asp:Label>
</FooterTemplate>
</asp:TemplateColumn>


'Code Behind
Private Sub dg_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles dg.ItemCreated
Dim elm As ListItemType
elm = e.Item.ItemType
Dim dr As DataRow, total As Double = 0
If elm = ListItemType.Footer Then
For Each dr In Me.dt.Select()
total = total + dr.Item("NoShares")
Next
Dim lbl As Label = e.Item.FindControl("lblTotal")
lbl.Text = Format(total, "#,##0")
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top