|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Bounded Datagrid and Subtotal rowsHello! Does anybody know how to add a subtotal row in a bounded datagrid?
Thanks! 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 Show quoteHide quote "josepm" wrote: > Hello! Does anybody know how to add a subtotal row in a bounded datagrid? > > Thanks! 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! Show quoteHide quote "Phillip Williams" wrote: > 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 > > -- > HTH, > Phillip Williams > http://www.societopia.net > http://www.webswapp.com > > > "josepm" wrote: > > > Hello! Does anybody know how to add a subtotal row in a bounded datagrid? > > > > Thanks!
Use windows control in asp.net 2.0
Adding controls to Pager row in GridView Re: How to get underlying data of TreeView control? (ASP.NET 2.0) Treeview control determining if node expanded or selected stylesheet on ASP.NET 2.0 TreeView and Menu Control ASP.NET 2.0 equivalent for e.Item.ItemIndex ? using placeholders want to create custom control using graphics Design Time Error: Error Rendering Control ValidateEvent bug with table and radio button |
|||||||||||||||||||||||