Return to the menu   Select another DES Module

Demonstrates the TotalingCalcItem

If you have to total a column in a ListView, GridView, DataList, or Repeater, you can use a PeterBlum.DES.Web.WebControls.TotalingCalcItem object in the CalculationController's expression. Just point TotalingCalcItem.ListControlID to the ID of the columnar control and TotalingCalcItem.ControlIDInRow to the ID of the field to total. That field can be any numeric textbox or a CalculationController.


Controls

This example uses a GridView. Each row has an integertextbox and a CalculationController.
Two more CalculationControllers are in the footer of the GridView. One totals the integertextboxes. The other totals the CalculationControllers in the columns.
Enter numbers into the 3 textboxes. Totals will change as you move focus off the textbox.

Integer: x 10: 10
Integer: x 10: 10
Integer: x 10: 10
Total: 3 30


Source Code (C#)

<script runat="server">
public void Page_Load(object sender, EventArgs e) { if (!IsPostBack) FillInList(); } public virtual void FillInList() { List<string> vData = new List<string>(); vData.Add("1"); vData.Add("2"); vData.Add("3"); GridView1.DataSource = vData; GridView1.DataBind(); } public void Button1_Click(object sender, EventArgs e) { if (PeterBlum.DES.Globals.WebFormDirector.IsValid) { // save the data FillInList(); // force the current value to be forgotten via ListView.OnDataBinding event } }
</script> This example uses a GridView. Each row has an integertextbox and a CalculationController.<br/> Two more CalculationControllers are in the footer of the GridView. One totals the integertextboxes. The other totals the CalculationControllers in the columns.<br/> Enter numbers into the 3 textboxes. Totals will change as you move focus off the textbox. <br/> <br/> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" ShowFooter="true" ShowHeader="false" BorderStyle="Solid" BorderWidth="1" BorderColor="Black"> <Columns> <asp:TemplateField> <ItemTemplate> Integer: <des:IntegerTextBox ID="IntegerTextBox1" runat="server" IntegerBindable="<%# 1%>"></des:IntegerTextBox> x 10: </ItemTemplate> <FooterTemplate> Total: <asp:Label ID="IntegersTotalLabel" runat="server"></asp:Label> <des:CalculationController ID="CalcIntegersTotal" runat="server" ShowValueControlID="IntegersTotalLabel" DecimalPlaces="Integer" AutoShowValue="Always"> <Expression> <des:TotalingCalcItem ControlIDInRow="IntegerTextBox1" ListControlID="GridView1" /> </Expression> </des:CalculationController> </FooterTemplate> </asp:TemplateField> <asp:TemplateField> <ItemTemplate> <asp:Label ID="TotalLabel" runat="server" /><br/> <des:CalculationController ID="CalcController1" runat="server" ShowValueControlID="TotalLabel" DecimalPlaces="Integer" AutoShowValue="Always"> <Expression> <des:NumericTextBoxCalcItem TextBoxControlID="IntegerTextBox1" /> <des:ConstantCalcItem Constant="10" Operator="Multiply" /> </Expression> </des:CalculationController> </ItemTemplate> <FooterTemplate> <asp:Label ID="CalcsTotalLabel" runat="server"></asp:Label> <des:CalculationController ID="CalcsTotalController" runat="server" ShowValueControlID="CalcsTotalLabel" DecimalPlaces="Integer" AutoShowValue="Always"> <Expression> <des:TotalingCalcItem ControlIDInRow="CalcController1" ListControlID="GridView1" /> </Expression> </des:CalculationController> </FooterTemplate> </asp:TemplateField> </Columns> </asp:GridView> <br/> <des:Button ID="Button1" runat="server" Text="Restart" OnClick="Button1_Click" />

Return to the menu   Select another DES Module