gridview合计问题

左手青春右手年华 左手青春右手年华 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
      <asp:GridView ID="gdvIn" CellSpacing="0" CellPadding="0" BorderStyle="None" 
CssClass="Contenttable" runat="server" AutoGenerateColumns="False"
ShowHeader="False" Width="100%" EnableTheming="false" GridLines="None">
<Columns>
<asp:BoundField DataField="categoryname" HeaderText="收支项目">
<ItemStyle CssClass="viewcateName"/></asp:BoundField>
<asp:TemplateField HeaderText="第1月">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("month1") %>' ForeColor='<%# returnColor(decimal.Parse(Eval("month1").ToString())) %>'></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="gridwidth"/>
</asp:TemplateField>
<asp:TemplateField HeaderText="第2月">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("month2") %>' ForeColor='<%# returnColor(decimal.Parse(Eval("month2").ToString())) %>'></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="gridwidth"/>
</asp:TemplateField>

---------------------------------------------分割线--------gdvIn和gdvOut是分别独立而非嵌套的Gridview--------------------------------------------
<asp:GridView ID="gdvOut" CellSpacing="0" CssClass="Contenttable"
runat="server" AutoGenerateColumns="False"
ShowHeader="False" Width="100%" EnableTheming="false" GridLines="None">
<Columns>
<asp:BoundField DataField="categoryname" HeaderText="收支项目">
<ItemStyle CssClass="viewcateName"/></asp:BoundField>
<asp:TemplateField HeaderText="第1月">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("month1") %>' ForeColor='<%# returnColor(decimal.Parse(Eval("month1").ToString())) %>'></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="gridwidth"/>
</asp:TemplateField>
<asp:TemplateField HeaderText="第2月">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("month2") %>' ForeColor='<%# returnColor(decimal.Parse(Eval("month2").ToString())) %>'></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="gridwidth"/>
</asp:TemplateField>
<asp:TemplateField HeaderText="第3月">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("month3") %>' ForeColor='<%# returnColor(decimal.Parse(Eval("month3").ToString())) %>'></asp:Label>
</ItemTemplate>


图1

图2


 //显示合计
int inCount = gdvIn.Rows.Count - 1;
int outCount = gdvOut.Rows.Count - 1;
for (int i = 1; i < gdvIn.Columns.Count;i++ )
{
Label lblIn = (Label)gdvIn.Rows[inCount].FindControl("Label"+i.ToString());
Label lblOut = (Label)gdvOut.Rows[outCount].FindControl("Label" + i.ToString());
Label lblSum = (Label)Page.FindControl("sum"+i.ToString());
decimal sum = decimal.Parse(lblIn.Text) - decimal.Parse(lblOut.Text);
lblSum.Text = sum.ToString("F2");
if(sum<0)
{
lblSum.ForeColor = System.Drawing.Color.Red;
}


问题是:1-11月都是收入小计和支出小计都是正确的,但12月不显示各自合计这是错误呢?思维定势了,求大侠们指点迷津。
...全文
评论 9
收藏 已收藏
分享
返回顶部
左手青春右手年华
.NET社区 62,272 成员 668,968 内容