Click here to Skip to main content
15,885,537 members
Please Sign up or sign in to vote.
4.00/5 (1 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:

ASP.NET
<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
Updated 4-Dec-19 23:22pm

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.
 
Share this answer
 
Comments
nizam qbixx 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 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.
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;
	}
}
 
Share this answer
 
<td><span runat="server" id="lbBranchname" style="font-style:italic;"><%# Eval("branchname")%></span>
</td>

HtmlGenericControl lbBranchname = e.Item.FindControl("lbBranchname") as HtmlGenericControl;
BranchName = lbBranchname.InnerText;
 
Share this answer
 
Comments
Richard Deeming 5-Dec-19 9:10am    
This unexplained code-dump has nothing to do with the (already solved) question.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900