M
Matthew
I have a SQLDataSource object declared in my ASPX page.
<asp:SqlDataSource ID="SqlDataSource1" runat="server" etc.. etc.. />
I pipe that query into a GridView, but I also want to populate the
footer with the sum of the [Cost] column. So, I modify the
RowDataBound event like so...
Function GetSum() As String
Dim Cmd As New OleDbDataAdapter(sumQuery, DataSource1.ConnectionString)
Dim Dat As New DataTable
Cmd.Fill(Dat)
Return Format(Dat.Rows(0)("Total"), "$#,####")
End Function
Protected Sub GridView1_RowDataBound(etc.. etc..) etc..
Select Case e.Row.RowType
Case DataControlRowType.Footer
e.Row.Cells(0).Text = "Total"
e.Row.Cells(5).Text = GetSum()
End Select
End Sub
Now in ASP.NET 1.0, I could use DataTable.Compute("Sum([Cost])", ""),
but ASP.NET 2.0's DataSource Object dosn't use a DataTable [or DataView]
(as far as I can see) so I am at a loss.
For now the above workaround works, but It makes another connection to
the DB to fetch the info I need. I would like to somehow access the
data from the datasource object. It obviously got the data when it
piped the results to the GridView so how can I access it.
Anyone have any ideas how I can do this ?
PS. I can't use GridView.Rows, it only contains the info thats displayed
in the grid. GridView.Rows.Count=10 when theres more then a hundred
rows returned by the query.
<asp:SqlDataSource ID="SqlDataSource1" runat="server" etc.. etc.. />
I pipe that query into a GridView, but I also want to populate the
footer with the sum of the [Cost] column. So, I modify the
RowDataBound event like so...
Function GetSum() As String
Dim Cmd As New OleDbDataAdapter(sumQuery, DataSource1.ConnectionString)
Dim Dat As New DataTable
Cmd.Fill(Dat)
Return Format(Dat.Rows(0)("Total"), "$#,####")
End Function
Protected Sub GridView1_RowDataBound(etc.. etc..) etc..
Select Case e.Row.RowType
Case DataControlRowType.Footer
e.Row.Cells(0).Text = "Total"
e.Row.Cells(5).Text = GetSum()
End Select
End Sub
Now in ASP.NET 1.0, I could use DataTable.Compute("Sum([Cost])", ""),
but ASP.NET 2.0's DataSource Object dosn't use a DataTable [or DataView]
(as far as I can see) so I am at a loss.
For now the above workaround works, but It makes another connection to
the DB to fetch the info I need. I would like to somehow access the
data from the datasource object. It obviously got the data when it
piped the results to the GridView so how can I access it.
Anyone have any ideas how I can do this ?
PS. I can't use GridView.Rows, it only contains the info thats displayed
in the grid. GridView.Rows.Count=10 when theres more then a hundred
rows returned by the query.