<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月不显示各自合计这是错误呢?思维定势了,求大侠们指点迷津。