ListView 有 DataSource 使用 DataPager 翻页


ListView有DataSource时,直接在 itemPlaceholder后面放一个DataPager即可翻页。

<asp:LinqDataSource ID="LinqDataSourceSoftware" runat="server" ContextTypeName="DataClassesDataContext" EntityTypeName="" OrderBy="SoftwareName desc" TableName="Softwares"></asp:LinqDataSource>
<asp:ListView ID="ListViewSoftwares" runat="server"
DataSourceID="LinqDataSourceSoftware"
OnItemCommand="ListViewSoftwares_ItemCommand">
<LayoutTemplate>
<table cellpadding="" runat="server" id="tblSoftLibrary" cellspacing="" class="ListView">
<tr runat="server">
<th runat="server" style="width:50%;"></th>
<th runat="server" style="width:50%;"></th>
</tr>
<tr runat="server" id="itemPlaceholder"/>
<tr runat="server">
<td colspan="">
<asp:DataPager runat="server" ID="DataPagerSoftwares"
PagedControlID="ListViewSoftwares"
PageSize=""
Class="ListViewPager" >
<Fields>
<asp:NextPreviousPagerField
ShowFirstPageButton="true"
FirstPageText="<<"
ShowNextPageButton="false"
ShowPreviousPageButton="false"/>
<asp:NumericPagerField ButtonCount="" />
<asp:NextPreviousPagerField
ShowLastPageButton="true"
LastPageText=">>"
ShowNextPageButton="false"
ShowPreviousPageButton="false"/>
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr runat="server" >
<td>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# ImagePathPrefix+Eval("ImagePath").ToString() %>' />
</td>
<td>
<asp:Label ID="LabelName" runat="server" Text='<%#Eval("SoftwareName") %>' Font-Bold="true"/>
</td>
</tr>
</ItemTemplate>
</asp:ListView>

ListView 无 DataSource 使用 DataPager 翻页


ListView无DataSource时,直接使用DataPager翻页,将会遇到以下问题

问题描述

点击两次才能翻页

翻页按钮点击一次后不会有任何反应,直到第二次点击后才翻页

返回上一页,内容为空

往前翻页,内容为空

而且翻页后的内容也是错的,第二页依然显示的是第一页开头几项

解决方法

这个问题的原因是DataPager找不到当前ListView的PageChangingProperty,所以我们得手动添加OnPagePropertiesChanging事件
OnPagePropertiesChanging

<asp:ListView ID="ListViewSoftwares" runat="server"
DataSourceID="LinqDataSourceSoftware"
OnItemCommand="ListViewSoftwares_ItemCommand"
OnPagePropertiesChanging="ListViewSoftwares_OnPagePropertiesChanging">
    protected void ListViewSoftwares_OnPagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
//set current page startindex, max rows and rebind to false
DataPagerSoftwares.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
//rebind ListView
BindListViewSoftwares();
}
protected void BindListViewSoftwares()
{
DataClassesDataContext da = new DataClassesDataContext();
var softwares = from s in da.EMS_Softwares
select s;
ListViewSoftwares.DataSource = softwares;
ListViewSoftwares.DataBind();
}

而且为了后台设置 DataPager 控件属性,我们得把DataPager控件挪出ListView

<asp:ListView ID="ListViewSoftwares" runat="server"
OnItemCommand="ListViewSoftwares_ItemCommand"
OnPagePropertiesChanging="ListViewSoftwares_OnPagePropertiesChanging">
<LayoutTemplate>
<table cellpadding="" runat="server" id="tblSoftLibrary" cellspacing="" class="ListView">
<tr runat="server">
<th runat="server" style="width:50%;"></th>
<th runat="server" style="width:50%;"></th>
</tr>
<tr runat="server" id="itemPlaceholder"/>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr runat="server" >
<td>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# ImagePathPrefix+Eval("ImagePath").ToString() %>' />
</td>
<td>
<asp:Label ID="LabelName" runat="server" Text='<%#Eval("SoftwareName") %>' Font-Bold="true"/>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
<tr runat="server">
<td colspan="">
<asp:DataPager runat="server" ID="DataPagerSoftwares"
PagedControlID="ListViewSoftwares"
PageSize=""
Class="ListViewPager" >
<Fields>
<asp:NextPreviousPagerField
ShowFirstPageButton="true"
FirstPageText="<<"
ShowNextPageButton="false"
ShowPreviousPageButton="false"/>
<asp:NumericPagerField ButtonCount="" />
<asp:NextPreviousPagerField
ShowLastPageButton="true"
LastPageText=">>"
ShowNextPageButton="false"
ShowPreviousPageButton="false"/>
</Fields>
</asp:DataPager>
</td>
</tr>

参考链接:http://weblogs.asp.net/hajan/paging-listview-using-datapager-without-using-datasource-control

ListView 无 DataSource 依然用 DataPager 翻页的更多相关文章

  1. ★android开发--ListView+Json+异步网络图片加载+滚动翻页的例子(图片能缓存,图片不错乱)

    例子中用于解析Json的Gson请自己Google下载 主Activity: package COM.Example.Main; import java.util.HashMap; import ja ...

  2. WPF中ListBox ListView数据翻页浏览笔记(强调:是数据翻页,非翻页动画)

    ListBox和ListView在应用中,常常有需求关于每页显示固定数量的数据,然后通过Timer自动或者手动翻页操作,本文介绍到的就是该动作的实现. 一.重点 对于ListBox和ListView来 ...

  3. 采用cocos2d-x lua 的listview 实现pageview的翻页效果之上下翻页效果

    --翻页滚动效果local function fnScrollViewScrolling( sender,eventType)    -- body    if eventType == 10 the ...

  4. yii2.0下,JqPaginator与load实现无刷新翻页

    JqPaginator下载地址http://jqpaginator.keenwon.com/ 控制器部分: <?php namespace backend\controllers; use co ...

  5. elementUI 列表里面含有多选框,当翻页的时候依然保持之前页多选不变

    el-table的type="selection"的使用 场景:el-table,type="selection"时,重新请求后,设置列表更新前的已勾选项 踩坑 ...

  6. ASP.NET使用ListView数据绑定控件和DataPager实现数据分页显示(二)

    使用ListView控件进行修改,删除与添加操作1.页面代码: <asp:ListView ID="lv2" runat="server" onpagep ...

  7. ASP.NET使用ListView数据绑定控件和DataPager实现数据分页显示(一)

    为什么使用ListView+DataPager的方式实现分页显示? .net提供的诸多数据绑定控件,每一种都有它自己的优点和缺点.如果需要对数据进行操作,如果数据量不大的情况下,DataList和Gr ...

  8. Android UI【android 仿微信、QQ聊天,带表情,可翻页,带翻页拖动缓冲】

    http://blog.csdn.net/lnb333666/article/details/8546497 如题,这是公司项目的一个功能模块,先上个效果图: 其次大致说说原理: 1,首先判断输入的字 ...

  9. 实现GridView翻页并且实现CheckBox选中功能的保持

    在GridView与数据库进行绑定后,由得到的数据记录可能有许多条,以至一个页面无法容纳,这时需要进行多页显. 要实现分页显现,只要使用分页类 "PagedDataSource" ...

随机推荐

  1. 数组的复制及ES6数组的扩展

    一.数组的复制 // alert([1,2,3]==[1,2,3]); let cc = [0,1,2]; let dd = cc; alert(dd==cc);//此时改变dd会影响cc ES5 只 ...

  2. 《深入理解Java虚拟机》——垃圾收集器与内存分配策略

    GC需要完成: 哪些内存需要回收 什么时候回收 如何回收 如何确定对象不再使用 引用计数算法 给对象添加一个引用计数器,当有一个地方引用它时,计数器值进行加1操作:当引用失效时,计数器值进行减1操作: ...

  3. python装饰器探究与参数的领取

    首先上原文, 现在,假设我们要增强now()函数的功能,比如,在函数调用前后自动打印日志,但又不希望修改now()函数的定义,这种在代码运行期间动态增加功能的方式,称之为"装饰器" ...

  4. elasticsearch 6 在 centos 6 上的安装问题

    ERROR: bootstrap checks failed max file descriptors [4096] for elasticsearch process likely too low, ...

  5. Redmine基础: 邮件配置

    1.用文本编辑器打开 D:\Bitnami\redmine-2.6.5-0\apps\redmine\htdocs\config\configuration.yml 文件,找到以下内容: 2.配置邮件 ...

  6. Python 脚本实现对 Linux 服务器的监控

    本文来自我的github pages博客http://galengao.github.io/ 即www.gaohuirong.cn 摘要: 原文地址 由于原文来自微信公众号,并且脚本都是图片,所以这里 ...

  7. ng组件通讯的几种方式

    通过输入型绑定把数据从父组件传到子组件. 如<app-hero-child *ngFor="let hero of heroes"  [hero]="hero&qu ...

  8. PV IP UV

    PV(访问量) Page View,页面浏览量. 具体的说,就是在一天内,该网站的页面总共访问了多少次 IP(独立IP) 一天内访问网站的IP数量 UV(独立访客) Unique Visitor 一般 ...

  9. Go语言学习_Win10下安装Go开发环境

    关于Go语言有多么值得学习,这里就不做介绍了,既然看了这篇文章,想必是对有学习意向. 这里是在Windows下安装Go环境,去中文社区的下载栏目,https://studygolang.com/dl ...

  10. java字符串以及字符类型基础

    介绍一下java字符集和字符的编码方式, 首先要区分一下字符集和字符编码.所谓的字符集 类似于unicode,GB2312,GBK,ASCII等等.因为一开始只有26个英文字母需要 编一下号.所有用下 ...