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. Vue的生命周期

    1.1.实例生命周期 每个 Vue 实例在被创建之前都要经过一系列的初始化过程.例如需要设置数据监听.编译模板.挂载实例到 DOM.在数据变化时更新 DOM 等.同时在这个过程中也会运行一些叫做生命周 ...

  2. 2018/1/19 Netty学习笔记(一)

    这段时间学了好多好多东西,不过更多是细节和思想上的,比如分布式事物,二次提交,改善代码质量,还有一些看了一些源码什么的; 记录一下真正的技术学习,关于Netty的学习过程; 首先说Netty之前先说一 ...

  3. jQuery源码研究——怎么看源码

    废话 这几天有想看源码的想法,于是就开始了源码的研究,经过几天的摸索发现看源码还是有点技巧在里面的,想着把这些东东写下来作为一个小总结. 在一个多月前我对Vue源码进行了一次研究,那时看源码的方式基本 ...

  4. Redis进阶实践之十一 Redis的Cluster集群搭建

    一.引言      本文档只对Redis的Cluster集群做简单的介绍,并没有对分布式系统的详细概念做深入的探讨.本文只是提供了有关如何设置集群.测试和操作集群的说明,而不涉及Redis集群规范中涵 ...

  5. Hive metastore源码阅读(二)

    最近随着项目的深入,发现hive meta有些弊端,就是你会发现它的元数据操作与操作物理集群的代码耦合在一起,非常不利于扩展.比如:在create_table的时候同时进行路径校验及创建,如下代码: ...

  6. xBIM WeXplorer xViewer的导航,相机、剖切、隐藏 等操作

    目录 基础 xBIM WeXplorer 简要介绍 xBIM WeXplorer xViewer 基本应用 xBIM WeXplorer xViewer 浏览器检查 xBIM WeXplorer xV ...

  7. Linux下yum安装MysqL数据库

    1.命令安装mysql # yum install mysql mysql-server mysql-devel -y 最后提示 Complete!  表示安装成功 2.查看是否生成了mysqld服务 ...

  8. 老男孩Python全栈开发(92天全)视频教程 自学笔记05

    day5课程内容: 集成开发环境(IDE) VIM #经典的Linux下的文本编辑器 Eclipse #Java IDE Visual Studio #微软开发的IDE notepad++ subli ...

  9. PAT乙级1065 map

    思路:检查某个客人是否有伴侣,如果有,伴侣是否也出现即可. 注意:0个单身狗的时候,不要输出多余的'\n', 否则会出现格式错误. AC代码 #include <stdio.h> #inc ...

  10. APICloud常用模块

    常用模块 基础 fs db 支付 wxPay aliPay unionPay 消息 ajpush rongCloud2