Using a standard ASP.NET ListView with a LinqDataSource and pagination enabled (with a DataPager), what would be the best way to default to displaying the last page of results?
You'll need to know the total record count and the number of records displayed on a page.
This helpful post shows you how to get the record count:
private LinqDataSourceSelectEventArgs args;
protected void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
args = e;
e.Result = new Database().Table.Whatever...
}
protected void LinqDataSource1_Selected(object sender, LinqDataSourceStatusEventArgs e)
{
this.label1.Text = args.Arguments.TotalRowCount + " records";
}
There's further discussion there of a situation that sounds similar to yours.
I've never done this, but there are several places I would look to see if I could make the change you want: an OnSelecting handler for the data source, OnPreRender or OnDataBinding for the ListView, and OnPreRender for the DataPager. Essentially, you want to handle the case of !IsPostBack
in a special way. I would probably look at the DataPager first and see if you can find out how many pages there are and set it to the last page. You may need to rebind the data source after setting the page to the one you want. After that I'd look at adding an OnDataBinding handler for the ListView and see what you can do there. I suspect that PreRender happens too late for the ListView to have any effect and OnSelecting, while good for filtering via a table-based function, probably won't do much good in this case.