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. 网络编程基础+UDP的实现

    网络地址分类(32位网络地址) A类地址:第一个字节为网络地址,其他3个字节主机地址,第一字节的最高位固定为0 从1.0.0.1------126.255.255.255 B类地址:第一字节和第二字节 ...

  2. php get_called_class()函数与get_class()函数的区别

    get_class (): 获取当前调用方法的类名: get_called_class():获取静态绑定后的类名: class Foo{ public function test(){ var_dum ...

  3. 数据库之mac上mysql root密码忘记或权限错误的解决办法

    [转自  http://blog.csdn.net/u014410695/article/details/50630233] 以下方法亲测有效,过程使用的工具只有mac的终端无需workbench 当 ...

  4. MYSQL 基础总结

    学习笔记 [mysql 是不区分大小写的,要区分可以用相应的函数:所有标点符号全是英文状态下的] 一.基础部分 //创建数据库 Create  database  database_name; //使 ...

  5. 十年磨一剑 Delphi重新崛起再写传奇

    新年伊始,英巴卡迪诺公司(Embarcadero)就在其官网发布了"激动人心的RAD Studio2018年发展规划"公告(见上图).公告中指出,将在于2018年第一季度发布10. ...

  6. CentOS 设置网络(修改IP&修改网关&修改DNS)

    CentOS修改IP地址 # ifconfig eth0 192.168.1.80 这样就把IP地址修改为192.168.1.80(如果发现上不了网了,那么你可能需要把网关和DNS也改一下,后面会提到 ...

  7. Java经典编程题50道之十六

    输出九九乘法表. public class Example16 {    public static void main(String[] args) {        table(9);    } ...

  8. Shiro笔记--shiroFilter权限过滤

    1.shiro中shiroFilter中的一些配置页面的过滤权限 <!--名字必须和web.xml里面的filter-name一样--> <bean id="shiroFi ...

  9. 2017CCPC 网络选拔赛1003 Ramsey定理

    Ramsey定理 任意6个人中,一定有三个人互为朋友,或者互相不是朋友. 证明 这里我就不证明了.下面链接有证明 鸽巢原理 Ramsey定理 AC代码 #include <stdio.h> ...

  10. Google2016 面试题 吹气球 区间dp

    题意:有n个气球,编号为0到n-1,每个气球都有一个分数,存在nums数组中.每次吹气球i可以得到的分数为 nums[left] * nums[i] * nums[right],left和right分 ...