统计单行或多行Gridview某列的总数

来源:互联网 发布:linux查看运行内存大小 编辑:程序博客网 时间:2024/06/04 17:11

前台代码:
                    <asp:Panel ID="Panel1" runat="server" Visible="false">
                        <div class="headresult">
                            <asp:Literal ID="ltResult1" runat="server"></asp:Literal>
                        </div>
                    </asp:Panel>


                    <asp:Panel ID="Panel2" runat="server" Visible="false">
                        <div class="headresult">
                            <asp:Literal ID="ltResult2" runat="server"></asp:Literal>
                        </div>
                    </asp:Panel>

后置代码:

DataTable   dt = MSCL.SqlHelper.GetDataTable(strSql);   //绑定Gridview中所有数据
        if (dt.Rows.Count > 0)   //如果Gridview中大于0条数据,则绑定并显示Panel(控制面板控件)里的值
        {
            #region
            string ProductCount = dt.Compute("sum(productnumber)", null).ToString();    //重点语句
            string PriceCount = dt.Compute("sum(prototalprcie)", null).ToString();
            string Blank = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
            Panel1.Visible = true;
            Panel2.Visible = true;
            string result = "查询" + begintime;
            result = result + (!string.IsNullOrEmpty(endtime) ? ("至" + endtime) : "");
            result = result + Blank + "商品数量总计:<span class='headresultred'>" + ProductCount + "</span>" + Blank + "商品金额总计:<span class='headresultred'>" + PriceCount + "</span>" + Blank;
            ltResult1.Text = result;
            ltResult2.Text = result;
            #endregion
        }
        else
        {
            Panel1.Visible = false;
            Panel2.Visible = false;
        }

0 0
原创粉丝点击