Click here to Skip to main content
Rate this: bad
good
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">
        <tr>
        <td>Size</td>
    <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource5">
        <ItemTemplate>
        <td><%# Eval("size_cd")%></td>       
        </ItemTemplate>
    </asp:Repeater>  
    <td>
    TOTAL
    </td>
    </tr>
    <tr> 
    <td>Allocated Quantity</td> 
    <asp:Repeater ID="Repeater2" runat="server" DataSourceID="SqlDataSource5" 
                    onitemcommand="Repeater2_ItemCommand1">
        <ItemTemplate>
        <td>
            <asp:Label ID="Label12" runat="server" Text='<%# Eval("allo_qty")%>'></asp:Label></td>       
        </ItemTemplate>
    </asp:Repeater>  
    <td>
        <asp:Label ID="LabelTotal" runat="server" Text=""></asp:Label>
    </td>
    </tr> 
    </table>
Posted 31-Jul-12 10:59am
Rate this: bad
good
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.
  Permalink  
Comments
nizam mazenan at 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.. :
1- http://aspdotnetcodebook.blogspot.com/2011/10/how-to-sum-value-of-gridview-column.html
2- http://aashishdynamic.wordpress.com/2011/12/17/gridview-column-total-on-onblur-event-using-javascript/
3- http://www.aspsnippets.com/Articles/Calculate-Row-Total-and-Grand-Total-in-ASPNet-GridView-using-jQuery.aspx
4- http://forums.asp.net/p/1635489/4221497.aspx
5- http://stackoverflow.com/questions/10120834/how-to-get-the-text-value-from-textbox-which-is-in-gridview-using-javascript
 
p/s: Number 5 sample i like most, but still fail to do it..
 
can anyone help me??
Christian Graus at 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
good
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;
	}
}
  Permalink  

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



Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 2 Aug 2012
Copyright © CodeProject, 1999-2014
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