By default, the last page in a ListView

Using a standard ASP.NET ListView with LinqDataSource enabled and pagination (using the DataPager), what would be the best way to display the last page of results by default?

+3
source share
3 answers

set the current page index to a page counter of 1.

+1
source

You need to know the total number of records and the number of records displayed on the page.

This useful post shows how to get a record counter:

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";
}

The following discusses a situation that is similar to yours.

+1
source

, , , : OnSelecting , OnPreRender OnDataBinding ListView OnPreRender DataPager. , !IsPostBackin a special way. I will 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 rebuild the data source after setting the page to the one you need. After that, I would look at adding an OnDataBinding handler for the ListView and see what you can do there. I suspect that PreRender is too late for ListView to have any effect and OnSelecting, although it is good for filtering through a table-based function, it probably won't do much good in this case.

+1
source

Source: https://habr.com/ru/post/1699174/


All Articles