【问题标题】:Displaying Total From Query in Footer of DataGrid在 DataGrid 的页脚中显示来自查询的总计
【发布时间】:2015-02-18 01:13:09
【问题描述】:

每次单击搜索按钮时,我都会运行一个查询。现在,我在页面数据网格下方的标签中显示了总数。我想在页脚的右侧显示总数。

ASP.NET:

<asp:TableCell>
    <asp:DataGrid ID="myGrid" runat="server"
        AutoGenerateColumns="True"
        BackColor="#E3DFD7"
        BorderColor="black"
        ShowFooter="false"
        CellPadding="3"
        CellSpacing="0"
        Font-Name="Calibri"
        HeaderStyle-Font-Bold="true"
        Font-Size="11pt"
        HeaderStyle-Font-Size="13pt"
        HeaderStyle-BackColor="#286090"
        HeaderStyle-ForeColor="white"
        EnableViewState="false" />
</asp:TableCell>

我知道我现在将页脚设置为 false,因为我没有使用它,但是有什么好方法可以将一个变量设置为我的数据网格页脚的总数?

【问题讨论】:

    标签: c# asp.net datagrid


    【解决方案1】:

    为您的页面中的页脚创建一个模板,如下所示:

     <FooterTemplate>
        <asp:Label ID="lblTotal" runat="server"/>
     </FooterTemplate>
    

    现在您可以为标签 lblTotal 分配一个值,例如在网格视图的 RowDataBound 事件中:

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
         if (e.Row.RowType == DataControlRowType.Footer)
         {
          Label lbl = (Label)e.Row.FindControl("lblTotal");
          lbl.Text = yourcalculatedValue.ToString();
         } 
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-05
      • 2010-09-05
      • 1970-01-01
      • 2021-02-22
      • 2017-12-10
      • 2016-08-04
      相关资源
      最近更新 更多