Bounded Datagrid and Subtotal rows

P

Phillip Williams

If you are using ASP.NET1.1, and you want a subtotal by page, then one way of
doing it would be to set the ShowFooter="True"on the datagrid and then to
calculate the page subtotal during the ItemDataBound event, e.g.

<asp:DataGrid ID="datagrid1" Runat="server" AutoGenerateColumns="False"
AllowPaging="True" PageSize="5" ShowFooter="True" >
<Columns>
<asp:TemplateColumn HeaderText="Sale Price">
<ItemTemplate >
<asp:Label id="lblSalePrice" Runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "SalePrice")%>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblTotal" Runat="server"></asp:Label>
</FooterTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

Private Sub DG_ItemDataBound(ByVal sender As Object, ByVal e As _
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
datagrid1.ItemDataBound
If (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem) Then
TotalSales += CType(e.Item.DataItem, DataRowView)("SalePrice")
End If
If ((e.Item.ItemType = ListItemType.Footer)) Then
Dim lbl As Label = CType(e.Item.FindControl("lblTotal"), Label)
If Not lbl Is Nothing Then
lbl.Text = "Total " & TotalSales.ToString("$#.00")
End If
End If
End Sub
 
J

josepm

Thanks Phillip!

You have focus the answer about a "grand total", but my goal is to obtain
subtotals grouping by a datagrid column. In any case, I take note about your
code!!!

Thank you!
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top