我有一个listview,它绑定到一个数据表。数据表在两个给定日期之间有记录。 我想在图片中显示明智地计算日总日期,但是每个记录之后的日总计显示...我想显示每个日期组的日总数。
这是我的代码..
<asp:ListView ID="lvRR" OnItemDataBound="lvRR_DataBound" OnItemCommand="lvRR_ItemCommand" runat="server" ItemPlaceholderID="plchldr" >
<LayoutTemplate>
<table id='tblViewDate' class='tblViewDate' align=center border=0 cellpadding=0 cellspacing=0 width=100% >
<tr class='GridviewScrollHeader'>
<th scope="col" style='min-width:150px !important;font-weight:bold' width="5%" align="left" valign="middle">
ID
</th>
<th scope="col" style='min-width:350px !important;font-weight:bold' align="left" valign="middle" >
From
</th>
<th scope="col" style='min-width:200px !important;font-weight:bold' align="left" valign="middle">
To
</th>
<th scope="col" style='min-width:100px !important;font-weight:bold' align="left" valign="middle">
Total Return Quantity
</th>
<th scope="col" style='min-width:100px !important;font-weight:bold' align="left" valign="middle">
Total Rejection Quantity <br />(In no. of Bottles)
</th>
</tr>
<tr id="plchldr" runat="server" />
</table>
</LayoutTemplate>
<ItemTemplate>
<asp:Panel runat="server" ID="pnlDate" Visible=true>
<tr id="Tr1" class='GridviewScrollItem GridviewScrollItem1' runat="server" ><%--visible='<%# Container.DataItemIndex.ToString()== "0" ? true : false %>'--%>
<td style='font-weight:bold;text-align:left;height:20px;font-size:12px;border-right:1px solid #686868 !important;' >
<asp:Label runat="server" ID="lblDate" Text='<%#Convert.ToDateTime(Eval("RejectDate")).ToString("dd-MMM-yyyy",System.Globalization.CultureInfo.InvariantCulture) %>'></asp:Label> </td>
<td style='font-weight:bold;text-align:left;height:20px;font-size:12px;border-right:1px solid #686868 !important;'> </td><td style='font-weight:bold;text-align:left;height:30px;font-size:12px;border-right:1px solid #686868 !important;'> </td><td style='font-weight:bold;text-align:left;height:30px;font-size:12px;border-right:1px solid #686868 !important;'> </td><td style='font-weight:bold;text-align:left;height:30px;font-size:12px;border-right:1px solid #686868 !important;'> </td>
</tr>
</asp:Panel>
<tr class='GridviewScrollItem'>
<td align="left" valign="middle" >
<asp:HiddenField ID="hidRRAutoID" runat="server" Value='<%# Eval("RRAutoID")%>' />
<asp:CheckBox runat="server" ID="chkSelect" />
<asp:Label ID="lnkRejectID" ToolTip="Click here to see details!" style="color:#2AA5BC;cursor:pointer" runat="server" Text='<%# Eval("Options").ToString()=="return" ? Eval("ReturnID") : Eval("RejectID") %>' ></asp:Label>
</td>
<td align="left" valign="middle" >
<asp:Label ID="lblFrom" runat="server" Text='<%# Eval("ReturnFrom") %>' ></asp:Label>
</td>
<td align="left" valign="middle" class="browsehhh555">
<asp:Label ID="lblTo" CssClass="link" runat="server" Text='<%# Eval("ReturnTo") %>' />
</td>
<td align="left" valign="middle" >
<asp:Label ID="lblTotalRejectQuantity" CssClass="link" runat="server" Text='<%# Eval("TotalReturnQuantity").ToString().Replace(".00","") %>' />
</td>
<td align="left" valign="middle" >
<asp:Label ID="Label1" CssClass="link" runat="server" Text='<%# Eval("TotalRejectQuantity").ToString().Replace(".00","") %>' />
</td>
</tr>
<asp:Panel runat="server" ID="pnlDayTotal" Visible=true>
<tr>
<td style="border-bottom:1px solid #AAAAAA"> </td><td style="border-bottom:1px solid #AAAAAA"> </td><td class='tdShift' style='text-align:right !important;height:20px !important;cursor:pointer;font-weight:bold;;white-space:nowrap;'>Day Total </td>
<td class='clsTotal' style='font-weight:normal;height:20px;text-align:right;width:100px !important;white-space:nowrap;'><asp:Literal runat="server" ID="ltrDayTotalReturn" Text="@"></asp:Literal></td>
<td class='clsTotal' style='font-weight:normal;height:20px;text-align:right;width:100px !important;white-space:nowrap;'><asp:Literal runat="server" ID="ltrDayTotalRejection" Text="#"></asp:Literal></td>
</tr>
</asp:Panel>
</ItemTemplate>
</asp:ListView>
Cs Part是......
public string temDate = ""; public string temDayTotal = ""; public string temDTDate = "";
protected void lvRR_DataBound(object sender, ListViewItemEventArgs e)
{
Label lblFrom = (Label)e.Item.FindControl("lblFrom");
Label lblTo = (Label)e.Item.FindControl("lblTo");
Panel pnlDate = (Panel)e.Item.FindControl("pnlDate");
Panel pnlDayTotal = (Panel)e.Item.FindControl("pnlDayTotal");
Label lblDate = (Label)e.Item.FindControl("lblDate");
if (pnlDate != null)
{
temDTDate = lblDate.Text.ToString();
if (lblDate.Text.ToString() == temDate)
{
pnlDate.Visible = false; //pnlDayTotal.Visible = false;
}
else
{
pnlDate.Visible = true; //pnlDayTotal.Visible = true;
}
temDate = lblDate.Text.ToString();
if (temDTDate != temDate)
{
pnlDayTotal.Visible = true;
}
}
}
请帮帮我......
答案 0 :(得分:0)
在绑定listview后添加以下代码..
decimal sTotalReturn =0; decimal sTotalReject =0;
for (Int32 ii = 0; ii < lvRR.Items.Count;ii++ )
{
Label lblTotalReturnQuantity = ((Label)lvRR.Items[ii].FindControl("lblTotalReturnQuantity"));
Label lblTotalRejectQuantity = ((Label)lvRR.Items[ii].FindControl("lblTotalRejectQuantity"));
Label lblDate = ((Label)lvRR.Items[ii] .FindControl("lblDate"));
Panel pnlDayTotal = ((Panel)lvRR.Items[ii].FindControl("pnlDayTotal"));
Literal ltrDayTotalReturn = ((Literal)lvRR.Items[ii].FindControl("ltrDayTotalReturn"));
Literal ltrDayTotalRejection = ((Literal)lvRR.Items[ii].FindControl("ltrDayTotalRejection"));
sTotalReturn = sTotalReturn + Convert.ToDecimal(lblTotalReturnQuantity.Text);
sTotalReject = sTotalReject + Convert.ToDecimal(lblTotalRejectQuantity.Text);
if (ii + 1 < lvRR.Items.Count)
{
Label lblDateNext = ((Label)lvRR.Items[ii + 1].FindControl("lblDate"));
if (lblDate.Text.ToString().Trim() != lblDateNext.Text.ToString().Trim())
{
pnlDayTotal.Visible = true;
ltrDayTotalReturn.Text = sTotalReturn.ToString();
ltrDayTotalRejection.Text = sTotalReject.ToString(); sTotalReturn = 0; sTotalReject = 0;
}
}
else
{
pnlDayTotal.Visible = true;
ltrDayTotalReturn.Text = sTotalReturn.ToString();
ltrDayTotalRejection.Text = sTotalReject.ToString();
sTotalReturn = 0; sTotalReject = 0;
}
}