ListView 无 DataSource 依然用 DataPager 翻页
ListView 无 DataSource 使用 DataPager 翻页
问题描述
点击两次才能翻页
返回上一页,内容为空
解决方法
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 翻页的更多相关文章
- ★android开发--ListView+Json+异步网络图片加载+滚动翻页的例子(图片能缓存,图片不错乱)
例子中用于解析Json的Gson请自己Google下载 主Activity: package COM.Example.Main; import java.util.HashMap; import ja ...
- WPF中ListBox ListView数据翻页浏览笔记(强调:是数据翻页,非翻页动画)
ListBox和ListView在应用中,常常有需求关于每页显示固定数量的数据,然后通过Timer自动或者手动翻页操作,本文介绍到的就是该动作的实现. 一.重点 对于ListBox和ListView来 ...
- 采用cocos2d-x lua 的listview 实现pageview的翻页效果之上下翻页效果
--翻页滚动效果local function fnScrollViewScrolling( sender,eventType) -- body if eventType == 10 the ...
- yii2.0下,JqPaginator与load实现无刷新翻页
JqPaginator下载地址http://jqpaginator.keenwon.com/ 控制器部分: <?php namespace backend\controllers; use co ...
- elementUI 列表里面含有多选框,当翻页的时候依然保持之前页多选不变
el-table的type="selection"的使用 场景:el-table,type="selection"时,重新请求后,设置列表更新前的已勾选项 踩坑 ...
- ASP.NET使用ListView数据绑定控件和DataPager实现数据分页显示(二)
使用ListView控件进行修改,删除与添加操作1.页面代码: <asp:ListView ID="lv2" runat="server" onpagep ...
- ASP.NET使用ListView数据绑定控件和DataPager实现数据分页显示(一)
为什么使用ListView+DataPager的方式实现分页显示? .net提供的诸多数据绑定控件,每一种都有它自己的优点和缺点.如果需要对数据进行操作,如果数据量不大的情况下,DataList和Gr ...
- Android UI【android 仿微信、QQ聊天,带表情,可翻页,带翻页拖动缓冲】
http://blog.csdn.net/lnb333666/article/details/8546497 如题,这是公司项目的一个功能模块,先上个效果图: 其次大致说说原理: 1,首先判断输入的字 ...
- 实现GridView翻页并且实现CheckBox选中功能的保持
在GridView与数据库进行绑定后,由得到的数据记录可能有许多条,以至一个页面无法容纳,这时需要进行多页显. 要实现分页显现,只要使用分页类 "PagedDataSource" ...
随机推荐
- IT连创业系列:年终回顾录!
一年不过一转眼,一光阴的青春又逝去了! 还有不到几天,就要进入新年快乐的祝福包围圈了. 在这归家之际,留文一篇,为这忙碌的一年创业留点回忆! IT连创业这一年走来: 大大小小的深坑,小小大大的困难,一 ...
- 微信小程序项目踩过的几个坑
一.前言 近期,开始了一段辛酸的还未开始就已经结束的"创业"(参见我的第二次创业,以梦为马,莫负韶华).大体上是开发了一款微信小程序,关于创业这件事情就不细说了,本文主要介绍一下开 ...
- Alex: 2018年对混合现实MR的展望
原文作者:Alex Kipman, 微软操作系统工程院技术院士 Hello 大家好! 难以置信我们已经走过了2018年的头两个月了. 每年一月份我都会去巴西省亲,和我的家人欢聚一堂,度过一个美好的假日 ...
- JS声明对象时属性名加引号与不加引号的问题
般情况下属性名加引号和不加引号是都可以的,效果是一样的. var obj = { name : '你好', 'age' : 1, }; document.write( obj['name'] + '& ...
- [Python Study Notes] 编程仪式感的Hello World!
学习还是要有一点仪式感的,学单片机第一步,点个灯:学编程第一步,hello world! C:\Users\Liu>python Python 3.6.4 (v3.6.4:d48eceb, De ...
- 金融&业务常识积累
前言 在项目中遇到很多名词,不太明白其含义.这些名词都是和金融领域紧密相关并且与项目的业务有着直接的联系.因此,决定通过搜集资料和归纳总结,对经后的工作产生一定的帮助. 常见的金融知识 PDL: Pa ...
- MySQL创建用户与授权
一. 创建用户 命令: CREATE USER 'username'@'host' IDENTIFIED BY 'password'; 说明: username:你将创建的用户名 host:指定该用户 ...
- httpd的三种模式比较
查看你的httpd使用了哪种模式: /usr/local/apache2/bin/httpd -V |grep 'Server MPM' 使用哪种模式,需要在编译的时候指定 --with-mpm=pr ...
- jq实现数字增加或者减少的动画
效果图: 1.HTML: <div class="up"></div> <br> <div class="down"& ...
- Centos下的GitLab的安装汉化和数据备份以及管理员密码重置
前言: 安装版本:gitlab-ce-8.8.5-ce.1.el7.x86_64.rpm 下载地址: https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yu ...