对于ASP.NET站点需要,最好是C#,但VB就可以了。
我想我们每天都会遇到像这样的情况。如果在绑定到ListView或其他类型的Dababindable对象的DataObject中少于PageSize项,则Pager作为UI是无用的。
所以问题:如何禁用它?
答案 0 :(得分:1)
当您的数据源的RowCount小于/等于Pager的PageSize时,您可以在Listview的DataBound事件中隐藏它。例如(伪代码,更改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
编辑:如果您使用了ObjectDataSource,则可以捕获其Selected Event以访问数据源(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
然后,您可以使用我上面的代码切换寻呼机的可见性。