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. C++ 关于字符串总结(持续更新)

    1.find_first_of size_type find_first_of( const basic_string &str, size_type index = 0 ); size_ty ...

  2. Dapper入门教程(二)——执行非查询语句

    描述 你可以从任意实现IDbConnection的类对象中调用Dapper的扩展方法"Execute".它能够执行一条命令(Command)一次或者多次,并返回受影响的行数.这个方 ...

  3. 【模板小程序】求第n个质数

    #include <iostream> #include <vector> using namespace std; int nth_prime(int n) { vector ...

  4. Javascript原型继承容易忽略的错误

    编写Javascript的开发者都知道,JS虽然没有类(ES6添加了class语法),但是可以模拟出OOP语言的类和面向对象的概念,比如我们都知道的一句话,Javascript中处处是对象,而面向对象 ...

  5. 关于HTML文档的文档模式

    HTML文档的文档模式包括混杂模式和标准模式,这两种模式主要影响CSS内容的呈现,但在某些情况下也会影响到JavaScript的解释执行. 如果在文档开始处没有发现文档类型声明,则所有浏览器都会默认开 ...

  6. 5、flask之信号和mateclass元类

    本篇导航: flask实例化参数 信号 metaclass元类解析 一.flask实例化参数 instance_path和instance_relative_config是配合来用的:这两个参数是用来 ...

  7. [NOIP2001提高组]数的划分

    题目描述 将整数n分成k份,且每份不能为空,任意两个方案不相同(不考虑顺序). 例如:n=7,k=3,下面三种分法被认为是相同的. 1,1,5; 1,5,1; 5,1,1; 问有多少种不同的分法. 输 ...

  8. es6变量声明和解构赋值

    /*声明: * 本文内容多为学习借鉴性内容,大部分非原创 * 特别感谢阮一峰的 ECMAScript6 入门,推荐大家学习 */ 一.es5变量声明的不足 1.变量提升和函数声明提升 es5的代码加载 ...

  9. Ehcache入门基础

    1.ehcache的简介  EhCache 是一个纯Java的进程内缓存框架,具有快速.精干等特点,是Hibernate中默认的CacheProvider. 2.ehcache入门实例 1.首先先导入 ...

  10. http权威指南笔记

    请求报文 响应报文GET /test/hi.txt HTTP/1.0 起始行 HTTP/1.0 200 OKAccept: text/* 首部 Content-type: text/plainAcce ...