分页时如何汇总,我想用数据显示的dataset,不想用 sum ,得到答案后马上结贴

dbx 2003-09-30 03:41:46
分页时如何汇总,我想用数据显示的dataset,不想用 sum ,得到答案后马上结贴
...全文
35 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
dbx 2003-09-30
  • 打赏
  • 举报
回复
seesea125(雨天) 说得好精采。
我的问题解决了。现在将分页汇总的心得总结如下。
1,根据sql语句得到dataset,在绑定dataset.tables.item(0).defaultview之前取得你要的汇总数据如下:
Private Sub bind()
Dim i As Integer
da = func1.getDataAdapter(sql.ToString)
ds = New DataSet
da.Fill(ds, "table0")
dg1.Style.Clear()
'********获得汇总数据

For i = 0 To ds.Tables(0).Rows.Count - 1
jimao_total += ds.Tables(0).Rows.Item(i).Item("技工贸总收入")
infact_total += ds.Tables(0).Rows.Item(i).Item("利润总额")
industry_total += ds.Tables(0).Rows.Item(i).Item("工业利润")
tax_total += ds.Tables(0).Rows.Item(i).Item("实际上缴税费总额")
yr_total += ds.Tables(0).Rows.Item(i).Item("营业税")
enterprise_total += ds.Tables.Item(0).Rows.Item(i).Item("企业所得税")
other_total += ds.Tables(0).Rows(i).Item("其他附加税费")
person_total += ds.Tables(0).Rows(i)("个人所得税")
Next
Response.Write(other_total)
dg1.DataSource = ds.Tables(0).DefaultView
dg1.DataBind()
End Sub
2.

2,在datagird的itemdatabound事件中。

执行以下代码:
‘+++++++++++showfooter=true
If e.Item.ItemType = ListItemType.Footer Then
e.Item.Cells(0).Text = jimao_total.ToString("C")
e.Item.Cells(1).Text = infact_total.ToString("C")
e.Item.Cells(2).Text = industry_total.ToString("C")
e.Item.Cells(3).Text = tax_total.ToString("C")
e.Item.Cells(4).Text = yr_total.ToString("C")
e.Item.Cells(5).Text = enterprise_total.ToString("C")
e.Item.Cells(6).Text = other_total.ToString("C")
e.Item.Cells(7).Text = person_total.ToString("C")
End If
因为datagrid.databind之后,才发生itemdatabound事件,所以取得数据一定要在datagridl.databind之前
dbx 2003-09-30
  • 打赏
  • 举报
回复
但是这这里有分页的,按照http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q313154

这里所说的。只能得到当页的汇总值,不能得到所有记录集的汇总值呀。
acewang 2003-09-30
  • 打赏
  • 举报
回复
HOW TO: Create a Summary Row for a DataGrid in ASP.NET
http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q313154
dbx 2003-09-30
  • 打赏
  • 举报
回复
Private Sub bind()
Dim i As Integer
da = func1.getDataAdapter(sql.ToString)
ds = New DataSet
da.Fill(ds, "table0")
dg1.Style.Clear()
dg1.DataSource = ds.Tables(0).DefaultView
dg1.DataBind()
'********获得汇总数据
For i = 0 To ds.Tables(0).Rows.Count - 1
viewstate("jimao_total") += ds.Tables(0).Rows.Item(i).Item("技工贸总收入")
'infact_total += ds.Tables(0).Rows.Item(i).Item("利润总额")
industry_total += ds.Tables(0).Rows.Item(i).Item("工业利润")
'tax_total += ds.Tables(0).Rows.Item(i).Item("实际上缴税费总额")
'yr_total += ds.Tables(0).Rows.Item(i).Item("营业税")
'enterprise_total += ds.Tables.Item(0).Rows.Item(i).Item("企业所得税")
'other_total += ds.Tables(0).Rows.Item(0).Item("其他附加税费")
'person_total += ds.Tables(0).Rows(i)("个人所得税")

Next
Response.Write(industry_total)
End Sub

这里是取到了值,但是放到Private Sub dg1_ItemDataBound 中值就丢失了。为何

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧