Need that for ASP.NET site, preferable C# but VB will be just fine.
I guess we all get into situation like this one on daily basis. Pager as UI开发者_开发百科 is useless if there is less than PageSize items in DataObject binded to ListView or other types of Dababindable objects.
So the question: how to disable it?
You could hide it in DataBound Event of your Listview when your Datasource's RowCount is less/equal the Pager's PageSize. For example(pseudo-code, change yourDataSource):
Private Sub ListView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.DataBound
Dim dataPager As DataPager = DirectCast(ListView1.FindControl("DataPager1"), DataPager)
dataPager.Visible = yourDataSource.Rows.Count > dataPager.PageSize
End Sub
EDIT: If you used an ObjectDataSource you can catch its Selected Event to access the Datasource (C#):
protected void ObjectDataSource1_Selected(object sender, ObjectDataSourceStatusEventArgs e)
{
// Get total count from the ObjectDataSource
DataTable dt = e.ReturnValue as DataTable;
int totalRecordCount = dt.Rows.Count;
}
VB:
Private Sub ObjectDataSource1_Selected(ByVal sender As Object, ByVal e As ObjectDataSourceStatusEventArgs) Handles ObjectDataSource1.Selected
' Get total count from the ObjectDataSource
Dim dt As DataTable = DirectCast(e.ReturnValue, DataTable)
Dim totalRecordCount As Int32 = dt.Rows.Count
End Sub
Then you can use my code above to switch visibility of the Pager.
精彩评论