当前位置:编程学习 > C#/ASP.NET >>

repeater ItemDataBound

这是我的aspx页面:

    <asp:Repeater ID="cart" runat="server" DataSourceID="ObjectDataSource1" 
            onitemdatabound="cart_ItemDataBound">
        <HeaderTemplate>
        <div id="checktitle"><ul><li class="remove">REMOVE</li><li class="item">ITEM</li><li class="remove">WEIGHT</li><li class="remove">QTY</li><li class="unitprice">UNIT PRICE</li><li class="unitprice">DISCOUNT</li><li class="total">TOTAL</li></ul></div>
        <div class="clear"></div>
        </HeaderTemplate>
        <ItemTemplate>
        <div id="checkitem"><ul>
        <li class="remove"><asp:CheckBox ID="remove" runat="server" /><asp:HiddenField ID="pid" Value='<%# Eval("Id") %>' runat="server" /></li>
        <li class="item"><asp:Label ID="product" Text='<%# Eval("Product") %>' runat="server" /></li>
        <li class="remove"><asp:Label ID="weight" Text='<%# Eval("Weight") %>' runat="server" /></li>
        <li class="remove"><asp:Label ID="qty" Text='<%# Eval("Qty") %>' runat="server" /></li>
        <li class="unitprice"><asp:Label ID="price" Text='<%# Eval("Price") %>' runat="server" /></li>
        <li class="unitprice"><asp:Label ID="discount" Text='<%# Eval("Discount") %>' runat="server" /></li>
        <li class="total"><asp:Label ID="total" Text='<%# total(Eval("Qty"),Eval("Price"),Eval("Discount")) %>' runat="server" /></li>
        <li><asp:Label ID="subtotal" Text="" runat="server" /></li>
        </ul></div>
        </ItemTemplate>
        <FooterTemplate>
        <asp:Label ID="lblEmptyData"
        Text="No Data To Display" runat="server" Visible="false">
 </asp:Label><div id="subtol">SUB TOTAL:<asp:Label ID="Subtotal" runat="server" Text=""></asp:Label><br />
 SUB WEIGHT:<asp:Label ID="Subweight" runat="server" Text=""></asp:Label></div></FooterTemplate>
        </asp:Repeater>
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" TypeName="Cart"
     SelectMethod="ShowShoppingCart">
    </asp:ObjectDataSource>

后台代码:
 protected void cart_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
            if (e.Item.ItemType == ListItemType.Footer)
            {
                Label subtotal = e.Item.FindControl("Subtotal") as Label;
                subtotal.Text=Subtotal.ToString();
                Label subweight = e.Item.FindControl("Subweight") as Label;
                subweight.Text = Subweight.ToString();
            }
            else if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                Label total = e.Item.FindControl("total") as Label;
                Subtotal +=Convert.ToSingle(total.Text);
               
                Label weight = e.Item.FindControl("weight") as Label;
                Subweight += Convert.ToSingle(weight.Text);
               
            }
          
      
    }
我想在Repeater的ItemDataBound计算产品的总价值与总重量,但Repeater总是不算第一行的值,它总是从第二行算起,例如:
product          weight     qty    unit price   discount     total
Ergo Pro         80          3      139.99        20%        $335.97
HydraTrack       65          2      59.99                    $119.98
Jogpal-Safety    75          6      49.99         10%        $269.946

                                                    SUB TOTAL:389.926
                                                    SUB WEIGHT:140

这是为什么啊?请各位大大帮帮忙,谢谢啊 --------------------编程问答-------------------- 还真没看出问题来  我自己试了一下  也没问题    帮你顶! --------------------编程问答-------------------- ASP.NET(C#)技术联盟高级群,欢迎工作中的朋友进来一起探讨并解决工作中遇到的问题!一群37078937(已满)二群37078867三群37078820(欢迎上海地区的朋友并爱好Dota的)
严禁加多群,群定期清理长期不发言不讨论的朋友,请多包涵。 --------------------编程问答-------------------- total这个方法在哪里
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,