2012-10-24 3 views
0

꼬리말에 lable 값을 표시 할 수 없습니다. 아래 코드는Gridview에 열의 합계를 표시 할 수 없습니다

Aspx 

<asp:GridView ID="gvallAccount" runat="server" AutoGenerateColumns="False" Width="589px" 
         OnRowDataBound="gvallAccount_RowDataBound" OnRowCommand="gvallAccount_RowCommand"> 
         <Columns> 
          <asp:TemplateField Visible="False"> 
           <ItemTemplate> 
            <asp:Label ID="lblAccountID" runat="server" Text='<%# Bind("ProductAccountID") %>'></asp:Label> 
           </ItemTemplate> 
          </asp:TemplateField> 
          <asp:TemplateField HeaderText="Name" Visible="True"> 
           <ItemTemplate> 
            <asp:Label ID="lblProductName" runat="server" Text='<%# Bind("ProductName") %>'></asp:Label> 
           </ItemTemplate> 
          </asp:TemplateField> 
          <asp:TemplateField HeaderText="Account Number" Visible="True"> 
           <ItemTemplate> 
            <asp:LinkButton ID="lnkAccCode" runat="server" Text='<%# Bind("ProductAccountCode") %>' 
             OnClick="lnkAccCode_Click" CommandName="gotoLink"></asp:LinkButton> 
           </ItemTemplate> 
          </asp:TemplateField> 
          <asp:TemplateField HeaderText="Account Value(KES)" Visible="True"> 
           <ItemTemplate> 
            <asp:Label ID="lblBalance" runat="server" Text='<%# Bind("BalanceToDate") %>'></asp:Label> 
           </ItemTemplate> 
           <FooterTemplate> 
            <asp:Label ID="lblTotal" runat="server"></asp:Label> 
           </FooterTemplate> 
          </asp:TemplateField> 
         </Columns> 
        </asp:GridView> 

C# Code 

protected void gvallAccount_RowDataBound(object sender, GridViewRowEventArgs e) 
    { 
     try 
     { 
      if (e.Row.RowType == DataControlRowType.DataRow) 
      { 
       decimal rowTotal = Convert.ToDecimal 
          (DataBinder.Eval(e.Row.DataItem, "BalanceToDate")); 
       grdTotal = grdTotal + rowTotal; 
      } 
      if (e.Row.RowType == DataControlRowType.Footer) 
      { 
       Label lblTotal = (Label)e.Row.FindControl("lblTotal"); 
       lblTotal.Text = grdTotal.ToString(); 
      } 
     } 
     catch (Exception Ex) 
     { 
      logger.Error("gvallAccount_RowDataBound : " + Ex.Message); 
     } 
    } 
+0

그리고 어떻게됩니까? 예외가 발생합니까? 0을 표시합니까? 아무 것도 표시되지 않습니까? – RobH

답변

0

GridView 태그에 ShowFooter = "True"속성이 있어야합니다.

<asp:GridView ID="gvallAccount" runat="server" AutoGenerateColumns="False" Width="589px" 
        OnRowDataBound="gvallAccount_RowDataBound" OnRowCommand="gvallAccount_RowCommand" ShowFooter="True"> 
관련 문제