我正在尝试将 July 列中的所有值汇总到 ID 为 july 的标签中。这是标记:
<asp:ListView ID="leaveListView" runat="server" ItemPlaceholderID="itemPlaceholder" OnItemDataBound="leaveListView_ItemDataBound">
<LayoutTemplate>
<table class="budgetList">
<thead>
<tr>
<td>Project Number</td>
<td>Account</td>
<td>Project Name</td>
<td>July</td>
</tr>
</thead>
<tbody>
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</tbody>
<tfoot>
<tr class="projectRowTotal">
<td>Project Totals</td>
<td></td>
<td></td>
<td><asp:Label ID="july" runat="server" Text=""></asp:Label></td>
</tr>
</tfoot>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr class="<%# Container.DataItemIndex % 2 == 0 ? "" : "even" %>">
<td><%# Eval("Project") %></td>
<td><%# Eval("Account") %></td>
<td><%# Eval("ProjectNumber") %></td>
<td><%# Eval("July") %></td>
</tr>
</ItemTemplate>
</asp:ListView>
我正在使用 ItemDataBound 事件求和,但它返回 null。这是代码隐藏:
decimal july = 0m;
protected void leaveListView_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
july += Convert.ToDecimal(e.Item.FindControl("July"));
}
Label julySum = (Label)leaveListView.FindControl("july");
julySum.Text = string.Format("{0:C}", (decimal?)july);
}
我需要做什么才能使其正常工作?