Click here to Skip to main content
12,947,324 members (45,837 online)
Rate this:
Please Sign up or sign in to vote.
Hye.. i have 1 problem that related to repeater in ASP.NET. im using repeater because i want my data to show like this:

Size : S M L XL
Quantity: 10 0 20 20

i have no problem to view like that.. my problem is, now i put one more column after the size/quantity that is TOTAL which is like this:

Size : S M L XL | TOTAL
Quantity: 10 0 20 20 | ...

but the total is still not working.. suppose the final result is like this:

Size : S M L XL | TOTAL
Quantity: 10 0 20 20 | 50

Can anyone help me??? here is my code:

<table border="1">
    <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource5">
        <td><%# Eval("size_cd")%></td>       
    <td>Allocated Quantity</td> 
    <asp:Repeater ID="Repeater2" runat="server" DataSourceID="SqlDataSource5" 
            <asp:Label ID="Label12" runat="server" Text='<%# Eval("allo_qty")%>'></asp:Label></td>       
        <asp:Label ID="LabelTotal" runat="server" Text=""></asp:Label>
Posted 31-Jul-12 9:59am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You have not written code to show the total, so what did you expect to happen ? You need to add an Eval for the Text, and have it call a method that generates the total and returns it.
nizam mazenan 1-Aug-12 11:19am
thanks Christian Graus for your help..
yes, i know, i not yet add any code to calculate. i have an idea but i just dont know how to do it. thats why i really need a simple code on how to calculate sum from the repeater.

im thinking of an idea to using java script, but i dont know hot to implement it..

Here i found the link that maybe help me.. i try few but no success until know.. :

p/s: Number 5 sample i like most, but still fail to do it..

can anyone help me??
Christian Graus 1-Aug-12 15:55pm
Looks to me like you found tons of help. So, stick to one example, write some code, and ask us for SPECIFIC help. OnItemCommand is part of the solution, one obvious way is to have an event for each item added, which sums the values, and then a code behind method to return the result.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

private void GridView2_DataBound(object sender, System.EventArgs e)
	foreach (object gv_loopVariable in GridView2.Rows) {
		gv = gv_loopVariable;
		Label TotalLabel = (Label)gv.FindControl("LabelTotal");
		Repeater repeaterSizeNQuatity = (Repeater)gv.FindControl("Repeater2");
		double totalquantity = 0;
		int counter = 0;
		counter = repeaterSizeNQuatity.Items.Count;
		for (int i = 0; i <= counter - 1; i++) {
			double quantity = 0;
			quantity = ((Label)repeaterSizeNQuatity.Items(i).FindControl("Label12")).Text;
			totalquantity = totalquantity + quantity;
		TotalLabel.Text = totalquantity;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 5,059
CHill60 3,235
Maciej Los 2,538
Jochen Arndt 1,935
ppolymorphe 1,795

Advertise | Privacy | Mobile
Web02 | 2.8.170518.1 | Last Updated 2 Aug 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100