Sending a datagrid's column

Discussion in 'ASP .Net Building Controls' started by keal75, Nov 8, 2005.

  1. keal75

    keal75 Guest

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

    Thanks
    --
    Koljas
    keal75, Nov 8, 2005
    #1
    1. Advertising

  2. 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

    *** Sent via Developersdex http://www.developersdex.com ***
    Davie James Paulino, Nov 8, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Hammond
    Replies:
    1
    Views:
    3,592
    bruce barker
    Nov 26, 2003
  2. Hai Nguyen
    Replies:
    0
    Views:
    380
    Hai Nguyen
    Jan 16, 2004
  3. Dexter
    Replies:
    1
    Views:
    403
    Eliyahu Goldin
    Jan 18, 2005
  4. John E.
    Replies:
    3
    Views:
    4,429
    masoud bayan
    Mar 25, 2005
  5. =?Utf-8?B?V2FyYW4=?=

    HyperLink Column and Button Column in a DataGrid

    =?Utf-8?B?V2FyYW4=?=, Aug 9, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    588
    =?Utf-8?B?V2FyYW4=?=
    Aug 9, 2005
Loading...

Share This Page