前台: <asp:DataList ID="DataList1" runat="server" Width="100%" CellPadding="0" DataKeyField="id"> <ItemTemplate> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="20" width="10%" class="but" align="center"><%# DataBinder.Eval(Container, "DataItem.fa_num ")%></td> <td height="20" width="40%" class="but" align="center"><asp:Label ID="LabelInventory" runat="server" Text='<%# Eval("Inventory") %>'></asp:Label></td> <td height="20" width="20%" class="but" align="center"><%# DataBinder.Eval(Container, "DataItem.selldata")%></td> <td height="20" width="20%" class="but" align="center"><asp:Label ID="LabelZF" runat="server" Text='<%# Eval("ZF") %>'></asp:Label></td> <td height="20px" width="10%" class="but" align="center"><asp:Label ID="LabelA" runat="server" Text="Label"></asp:Label></td> </tr> </table> </ItemTemplate> </asp:DataList>
后台: public void BindData() { .............. ss(); .............. }
protected void ss() { float Labelnum = 0; for (int i = 0; i <= DataList1.Items.Count - 1; i++) { Labelnum += Convert.ToSingle(((Label)this.DataList1.Items[i].FindControl("LabelInventory")).Text); ((Label)this.DataList1.Items[i].FindControl("LabelA")).Text = Labelnum.ToString(); } }
|