Number of rows returned from ObjectDataSource.FilterExpression

J

John

How can I find how many rows are returned from the DataView generated by
FilterExpression on an ObjectDataSource?

I can get the number of rows in the underlying datatable by using:

protected void mydataSource_Selected(object sender,
ObjectDataSourceStatusEventArgs e)
{
numrows = ((DataTable) e.ReturnValue).Rows.Count;
}

But I can't get access to the dataview used by FilterExpression. It's not
((DataTable) e.ReturnValue).DefaultView

Thanks,

John
 
J

John

I double checked, e.ReturnValue is a strongly typed datatable, not a
dataview.

I found that calling objDataSource.Select() returns a dataview with the
filter applied, *but* this seems to result in a double call with the built
in databinding - unless you turn caching on.

Any ideas how to avoid the double call?

John
 
J

John

This seems to work, but it's a bit clunky:

If the only way to get the dataview is to call objDataSource.Select(), we
need to prevent the automatic databinding, otherwise a second SQL call will
result. I did the following in Page_PreRender:

DataView dv = myDataSource.Select() as DataView;
myDataSource.DataSourceID = null; // break the auto-binding
amyDataSource.DataSource = dv; // allow it to respond to manual
binding
DataBind();

This results in only one call to the SQL, and a dataview you can work with.

It would be so much better if this was made available in
ObjectDataSource.Selected

John
 
J

John

But changing the binding from GridView.DataSourceID to DataSource seems to
break sorting.

Ho hum.

I'll have to go back to caching the result for a couple of seconds between
the two calls to ObjectDataSource.Select() (my manual call, then the
automatic databinding one).

There must be a better way!!!

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top