From: JimLad on
Hi,

I have a listview on a page which binds to an objectdatasource which
returns a typed datatable as the select command. There are also
Update, Insert and Delete commands.
I need to display the sum of a couple of these columns and a max and
min of another column.
What is the best way of doing this?

I could:
- Hack around with the listview.
- Run Compute on the datatable.
- Run separate aggregating sproc on the source database.

The middle one seems to be best but I can't see how to get access to
the datatable without causing another call to the database
(essentially calling GetData twice on the tableadapter - once manually
and once thropugh the automated databind). The datatable is not
accessible from the listview or the objectdatasource as far as I can
tell (databind is handled automatically and I don't really want to do
it manually).

Thanks in advance for any help.

James




From: JimLad on
On 19 May, 17:15, JimLad <jamesdbi...(a)yahoo.co.uk> wrote:
> Hi,
>
> I have a listview on a page which binds to an objectdatasource which
> returns a typed datatable as the select command.  There are also
> Update, Insert and Delete commands.
> I need to display the sum of a couple of these columns and a max and
> min of another column.
> What is the best way of doing this?
>
> I could:
> - Hack around with the listview.
> - Run Compute on the datatable.
> - Run separate aggregating sproc on the source database.
>
> The middle one seems to be best but I can't see how to get access to
> the datatable without causing another call to the database
> (essentially calling GetData twice on the tableadapter - once manually
> and once thropugh the automated databind). The datatable is not
> accessible from the listview or the objectdatasource as far as I can
> tell (databind is handled automatically and I don't really want to do
> it manually).
>
> Thanks in advance for any help.
>
> James

Why is it that you spent hours thinking about something and it becomes
clear the moment you put it on a newsgroup? Doh!
The key is the ObjectDataSource.Selected event. e.ReturnValue give you
your datatable or whatever else is the datasource.

Private Sub ObjectDataSource_Selected(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs)
Handles ObjectDataSource.Selected
Dim dataTable As DataTable = CType(e.ReturnValue, DataTable)
TotalLabel.Text = dataTable.Compute("Sum(total)", "").ToString
Dim minEndDateObjectAs Object =
dataTable.Compute("Min(end_date)", "")
If MinEndDateTextBox.Text = "" AndAlso
IsDate(minEndDateObject) Then
MinEndDateTextBox.Text =
CDate(minEndDateObject).ToString("d")
End If
End Sub

James