首页 新闻 搜索 专区 学院

asp.net datalist怎么增加一行合计

0
[已解决问题] 解决于 2011-12-21 09:13

目前我的表格是这样的:

ID      数量      损耗量

01     1000     50

02      200       2

想要得到的效果是:

ID      数量      损耗量

01     1000     50

02      200       2

合计     1200     52

 

ID、数量、损耗量这3列的数据是从数据库得到的,不知道怎么做合计这一列

菜鸟一个,希望高手指点一下,给个示例代码看看。谢谢了

Mr.ch的主页 Mr.ch | 初学一级 | 园豆:6
提问于:2011-12-19 22:05
< >
分享
最佳答案
0

跟今天的一个问题一样,我在这个问题中回复了:http://q.cnblogs.com/q/30748#ans63907

artwl | 专家六级 |园豆:16536 | 2011-12-20 18:33
其他回答(2)
0
主要是2个datatable的合并

        DataTable DataTable1 = SqlHelper.GetDataTable("select id,num from testSum");
DataTable DataTable2 = SqlHelper.GetDataTable("select Sum(id),Sum(num) from testSum");
DataTable newDataTable = DataTable1.Clone();

object[] obj = new object[newDataTable.Columns.Count];
for (int i = 0; i < DataTable1.Rows.Count; i++)
{
DataTable1.Rows[i].ItemArray.CopyTo(obj, 0);
newDataTable.Rows.Add(obj);
}
for (int i = 0; i < DataTable2.Rows.Count; i++)
{
DataTable2.Rows[i].ItemArray.CopyTo(obj, 0);
newDataTable.Rows.Add(obj);
}
GridView1.DataSource = newDataTable;
GridView1.DataBind();
myurl | 园豆:225 (菜鸟二级) | 2011-12-19 23:35

这里的回复修改好像有点问题,楼主参考

http://www.cnblogs.com/myurl/archive/2011/12/19/MergeDataTable.html

支持(0) 反对(0) myurl | 园豆:225 (菜鸟二级) | 2011-12-19 23:53
1

  protected void gv_lokConsumeStatisic_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        ConsumeStatisic item = (ConsumeStatisic)e.Row.DataItem;

        if (e.Row.RowType == DataControlRowType.DataRow)
        {

  if (item.小计 == 0m)
            {
                e.Row.Cells[0].Text = String.Format("{0}-{1}-{2}", ViewState["year"].ToString(), (int.Parse(ViewState["month"].ToString())).ToString("d2"), item.天数.ToString("d2"));
                e.Row.Cells[1].Text = String.Empty;
                e.Row.Cells[2].Text = String.Empty;
                e.Row.Cells[3].Text = String.Empty;
                e.Row.Cells[4].Text = String.Empty;
                e.Row.Cells[5].Text = String.Empty;
            }
            else
            {
                total.本店消费 += item.本店消费;
                total.联乐消费 += item.联乐消费;
                total.普通顾客消费 += item.普通顾客消费;
                total.外送消费 += item.外送消费;
                total.小计 += item.小计;

 

     if (e.Row.RowType == DataControlRowType.Footer)
        {
            e.Row.Cells[0].Text = "合计";
            e.Row.Cells[1].Text = total.本店消费.ToString("c");
            e.Row.Cells[2].Text = total.联乐消费.ToString("c");
            e.Row.Cells[3].Text = total.普通顾客消费.ToString("c");
            e.Row.Cells[4].Text = total.外送消费.ToString("c");
            e.Row.Cells[5].Text = total.小计.ToString("c");

            e.Row.Cells[0].HorizontalAlign = HorizontalAlign.Center;
            e.Row.Cells[1].HorizontalAlign = HorizontalAlign.Right;
            e.Row.Cells[2].HorizontalAlign = HorizontalAlign.Right;
            e.Row.Cells[3].HorizontalAlign = HorizontalAlign.Right;
            e.Row.Cells[4].HorizontalAlign = HorizontalAlign.Right;
            e.Row.Cells[5].HorizontalAlign = HorizontalAlign.Right;
        }

悟行 | 园豆:12427 (专家六级) | 2011-12-20 10:15
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册