http://xml.sz.luohuedu.net/xml/ShowDetail.asp?id=149E5DD7-3B32-461e-ACC6-51D1652E6746

解决方案 »

  1.   

    用DataGrid嵌套DataGrid/DataList实现应该会更方便一点
    http://xml.sz.luohuedu.net/xml/ShowDetail.asp?id=149E5DD7-3B32-461e-ACC6-51D1652E6746
      

  2.   

    3、另外,如何在SQL语句中用SUM求和,我用select sum(bookprice),bookname from book怎么不行呢?select sum(bookprice),bookname from book
    你的写法无错
    需要bookprice为数值型,另外不能有空值才能正确.
      

  3.   

    用DataGrid嵌套DataGrid/DataList实现应该会更方便一点
      

  4.   

    求和sum 好象要和 group by 一起使用
    select sum(bookprice),bookname from book group by bookname;
      

  5.   

    在ASP.NET中可以後期邦定數據,給你一段代碼參考。
    Private Sub AddCompDeviceTotal()
            Dim n2 As Integer
            Dim intTotal2 As Integer = 0
            Dim intColumn2 As Integer = 0
            Dim intSubTotal2 As Integer = 0
            'Dim iNew As Integer = 0
            intTotal2 = dgDeviceTotal.Items.Count
            Dim bAddNew2 As Boolean
            If dgDeviceTotal.Items.Count > 0 Then
                For n2 = 0 To dgDeviceTotal.Items.Count - 1
                    intSubTotal2 += CInt(dgDeviceTotal.Items(n2).Cells(5).Text)
                    If n2 = dgDeviceTotal.Items.Count Then
                        bAddNew2 = True
                    Else
                        Try
                            bAddNew2 = dgDeviceTotal.Items(n2).Cells(1).Text <> dgDeviceTotal.Items(n2 + 1).Cells(1).Text And dgDeviceTotal.Items(n2).Cells(1).Text <> ""
                        Catch ex As Exception
                            bAddNew2 = True
                        End Try
                    End If
                    If bAddNew2 Then
                        Dim diSubTotal2 As DataGridItem = New DataGridItem(n2, 0, ListItemType.Item)
                        diSubTotal2.CssClass = "mTrTotal"
                        For intColumn2 = 0 To dgDeviceTotal.Items(0).Cells.Count - 1
                            Dim tcNew As TableCell = New TableCell()
                            diSubTotal2.Cells.Add(tcNew)
                        Next
                        With diSubTotal2
                            .Cells(0).Text = ""
                            .Cells(1).Text = dgDeviceTotal.Items(n2).Cells(1).Text & "  合計﹕" & intSubTotal2.ToString
                            .Cells(2).Text = ""
                            .Cells(3).Text = ""
                            .Cells(4).Text = ""
                            .Cells(5).Text = ""
                        End With
                        dgDeviceTotal.Controls(0).Controls.AddAt(n2 + iNew2 + 2, diSubTotal2)
                        intSubTotal2 = 0
                        iNew2 += 1
                    End If
                Next
            End If
        End Sub
      

  6.   

    http://www.csdn.net/develop/Read_Article.asp?Id=20221
      

  7.   

    3.select sum(bookprice) from book group by bookname
    必须用group by成组的,另选出列也须是组表达式,类似的像sum,count
      

  8.   

    2、3没问题了。
    最主要的是问题1:我的合计行不在库里,怎么用嵌套DATAGRID的方法呢?那好象之间有主从关系,可不可以用SQL语句来实现呢?
    我需要是绑定一个月的数据后就添加合计行计算之前所有月份的值。
     日期    数目
    ——------------
     1-2      23.2
     1-3      2.2
     ...       ...
     合计     ...
     2-1       122
     2-2        12
    ...       ...
    合计       ...
      

  9.   

    1-2      23.2
     1-3      2.2
     ...       ... 2-1       122
     2-2        12
     ...       ...
     合计       ...
    --------------------------
    如果是在最后有一个汇总,可以使用"页脚"。
    你这种情况是不是要根据条件望DataGrid加新记录了。
    具体没做过你这种的,不敢随便说话。
    可以这样考虑一下:
    在itemdatabind事件里,按月份统计记录条数,在相应的记录后面加当月的汇总
    -------------------------
    具体你可以参考 孟子E章 的文章,他那里有不少关于DataGrid的
      

  10.   

    http://www.asp.net的这篇文章也许有用
    Summary Rows in DataGrid Controls
      

  11.   

    用sql实现,我现在没有调试环境,若可行请结贴!!!
    select bookdate,bookamt from 
    (
    select bookdate=CONVERT(varchar(10), bookdates,120),bookamt=sum(bookprice) from book group by CONVERT(varchar(10), bookdates,120)
    union 
    select bookdate=CONVERT(varchar(8), bookdates,120)+'32',bookamt=sum(bookprice) from book group by CONVERT(varchar(8), bookdates,120)+'32'
    ) as a order by bookdate
    然后在绑定的事件时判断当日期为32时改为合计,或在绑定前先将dataset的datatable的bookdate的侄的后两位是32时替换成合计
      

  12.   

    我已经解决了,不过用的方法比较笨,先判定位置,再插入合计的数据.
    wyfwyf2000(求知),你的方法我会试一试,谢谢各位!都会给分!