Asp.net gridview页脚摘要 [英] Asp.net gridview footer summary

查看:60
本文介绍了Asp.net gridview页脚摘要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

检查我的页脚摘要代码,我不知道有什么问题请帮帮我。



check my footer summary code , I don't know what is the problem please help me.

protected void grvList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (e.Row.RowIndex + 1).ToString();

            }

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label WORKHRS = (Label)e.Row.FindControl("WORKHRS");
                int qty = Int32.Parse(WORKHRS.Text);
                total = total + qty;
            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                Label lblTotalhours = (Label)e.Row.FindControl("WORKHRS");
                lblTotalhours.Text = total.ToString();
            }
        }





----------------- ---------------------------------------------





--------------------------------------------------------------

<asp:GridView ID="grvList" runat="server" AutoGenerateColumns="False" CssClass="gridview" GridLines="Horizontal" ShowFooter="true"  OnRowDataBound="grvList_RowDataBound" PageSize="5">
       <AlternatingRowStyle CssClass="alternate" />
       <Columns>
           <asp:BoundField HeaderText="Sl. No."></asp:BoundField>
           <asp:BoundField DataField="WorkDate" DataFormatString="{0:dd-MMM-yyyy}" HeaderText="WorkDate">
               <HeaderStyle Width="150px" />
           </asp:BoundField>
           <asp:BoundField DataField="InTime" DataFormatString="{0:HH:mm tt}" HeaderText="In Time">
               <HeaderStyle Width="150px" />
           </asp:BoundField>
           <asp:BoundField DataField="OutTime" DataFormatString="{0:HH:mm tt}" HeaderText="Out Time">
               <HeaderStyle Width="150px" />
           </asp:BoundField>


           <%--<asp:BoundField DataField="WORKHRS" HeaderText="Hours"></asp:BoundField>--%>
         <asp:TemplateField HeaderText="WORKHRS">
        <ItemTemplate>
           <div>
           <asp:Label ID="WORKHRS" runat="server" Text='<%# Bind("WORKHRS") %>' />
           </div>
        </ItemTemplate>
        <FooterTemplate>
           <div style="text-align: right;">
           <asp:Label ID="lblTotalhours" runat="server" />
           </div>
        </FooterTemplate>
     </asp:TemplateField>


       </Columns>
    <FooterStyle BackColor="#cccccc" Font-Bold="True" ForeColor="Black" HorizontalAlign="Left" />
       <EmptyDataTemplate>
           <div class="gridviewblank">Oops!. There is no data to display.</div>
       </EmptyDataTemplate>

   </asp:GridView>

推荐答案

原因是:您找到的标签不是在页脚模板中定义。您在页脚中定义了lblTotalhours标签,但找到了WorkHrs



这是您的解决方案:

Reason is :You are finding a Label which is not defined in footer template. You defined "lblTotalhours" Label in footer but finding "WorkHrs"

Here is your solution:
protected void grvList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (e.Row.RowIndex + 1).ToString();
 
            }
 
            else if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label WORKHRS = (Label)e.Row.FindControl("WORKHRS");
                int qty = Int32.Parse(WORKHRS.Text);
                total = total + qty;
            }
            else (e.Row.RowType == DataControlRowType.Footer)
            {
               // here you are finding a Label which is not defined in footer template. 
               
                Label lblTotalhours = (Label)e.Row.FindControl("lblTotalhours");
                lblTotalhours.Text = total.ToString();
            }
        }


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  {
      float grand_total=0;
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              e.Row.Cells[0].Text = (e.Row.RowIndex + 1).ToString();

          }
      if (e.Row.RowType == DataControlRowType.DataRow)
      {
          Label WORKHRS = (Label)e.Row.FindControl("WORKHRS");


          grand_total += float.Parse(WORKHRS.Text);

      }
      if (e.Row.RowType == DataControlRowType.Footer)
      {
          Label WORKHRS1= (Label)e.Row.FindControl("WORKHRS1");
          WORKHRS1.Text = grand_total.ToString();
      }
  }


这篇关于Asp.net gridview页脚摘要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆