《ASP.NET1200例》<asp:DataList>分页显示图片
aspx页面代码
<asp:DataList ID="dlPhoto" runat="server" Height="137px"
Width="277px" onitemcommand="dlPhoto_ItemCommand" RepeatDirection="Horizontal">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "imageUrl") %>
<asp:ImageButton ID="ImageButton1" ImageUrl="image/20131128.jpg" Height="100px" Width ="200px" runat="server" /><br />
<asp:Label ID="Label1" runat="server" >相册名称</asp:Label>
<asp:ImageButton id="ProductImage" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "imageUrl") %>' Height="100px" Width ="200px" runat="server"/>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="LinkButton1" CommandName="first" runat="server" >首页</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" CommandName="pre" runat="server">上一页</asp:LinkButton>
<asp:LinkButton ID="LinkButton3" CommandName="next" runat="server">下一页</asp:LinkButton>
<asp:LinkButton ID="LinkButton4" CommandName="last" runat="server">末页</asp:LinkButton>
<asp:TextBox ID="txtPage" runat="server" Height="18px" Width="34px"></asp:TextBox>
<asp:LinkButton ID="LinkButton5" CommandName="search" runat="server">Go</asp:LinkButton>
</FooterTemplate>
</asp:DataList>
aspx.cs
public partial class _232DataList : System.Web.UI.Page
{
PagedDataSource pds = new PagedDataSource();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindDL(); }
}
public void bindDL(int curPage)
{ pds.AllowPaging = true;
pds.PageSize = ;
pds.CurrentPageIndex = curPage; //绑定数据源
ShowImageBll ShowImageBll = new BLL.ShowImageBll();
DataSet ds=ShowImageBll.GetList();
pds.DataSource = ds.Tables[].DefaultView;
dlPhoto.DataSource = pds;
dlPhoto.DataBind(); } protected void dlPhoto_ItemCommand(object source, DataListCommandEventArgs e)
{ switch (e.CommandName)
{
case "first":
if (pds.CurrentPageIndex != )
{
pds.CurrentPageIndex = ;
}
else
{
Response.Write("<script language=javascript>" + "alert(\"已经是第一页\")" + "</script>");
}
bindDL(pds.CurrentPageIndex);
break;
case "pre":
if (pds.CurrentPageIndex > ) {
pds.CurrentPageIndex = pds.CurrentPageIndex - ;
bindDL(pds.CurrentPageIndex);
}
else
{
Response.Write("<script language=javascript>" + "alert(\"已经是第一页\")" + "</script>");
} break;
case "next":
if (pds.CurrentPageIndex < pds.PageCount - )
{
pds.CurrentPageIndex = pds.CurrentPageIndex + ;
bindDL(pds.CurrentPageIndex);
}
else
{
Response.Write("<script language=javascript>" + "alert(\"已经是最后一页\")" + "</script>");
} break;
case "last":
if (pds.CurrentPageIndex != pds.PageCount - )
{
pds.CurrentPageIndex = pds.PageCount - ; }
else
{
Response.Write("<script language=javascript>" + "alert(\"已经是最后一页\")" + "</script>");
}
bindDL(pds.CurrentPageIndex);
break;
case "search":
if (e.Item.ItemType == ListItemType.Footer)
{
int pageCount = int.Parse(pds.PageCount.ToString ());
TextBox txtPage = e.Item.FindControl("txtPage") as TextBox;
int myPage = ;
if(txtPage .Text !=null)
{
myPage = int.Parse(txtPage .Text.Trim ().ToString ()); }
if (myPage <=||myPage >pageCount ) {
Response .Write ("<script>alert('请输入正确的页面数!')</script>"); }
bindDL(myPage-); }
break;
}
} }
数据库设计

运行效果

期间出现的问题:
【1】数据库imageUrl字段 应该为image/20131128.jpg 无需加引号
【2】路径的读取ImageUrl='<%# DataBinder.Eval(Container.DataItem, "imageUrl") %>'
【3】读取图片出错时,应该点击页面上那个叉图片的属性,查看读取出来的路径再查错-------这点很重要
【4】遗留问题:分页显示依然存在Bug后续将做更改 V20131204版本
Asp.net提供了三个功能强大的列表控件:DataGrid、DataList和Repeater控件,但其中只有DataGrid控件提供分页功能。相对DataGrid,DataList和Repeater控件具有更高的样式自定义性,所以很多时候我们喜欢使用DataList或Repeater控件来显示数据。
注: PagedDataSource 类的部分公共属性:
AllowCustomPaging 获取或设置指示是否启用自定义分页的值。
AllowPaging 获取或设置指示是否启用分页的值。
Count 获取要从数据源使用的项数。
CurrentPageIndex 获取或设置当前页的索引。
DataSource 获取或设置数据源。
DataSourceCount 获取数据源中的项数。
FirstIndexInPage 获取页中的第一个索引。
IsCustomPagingEnabled 获取一个值,该值指示是否启用自定义分页。
IsFirstPage 获取一个值,该值指示当前页是否是首页。
IsLastPage 获取一个值,该值指示当前页是否是最后一页。
IsPagingEnabled 获取一个值,该值指示是否启用分页。
IsReadOnly 获取一个值,该值指示数据源是否是只读的。
IsSynchronized 获取一个值,该值指示是否同步对数据源的访问(线程安全)。
PageCount 获取显示数据源中的所有项所需要的总页数。
PageSize 获取或设置要在单页上显示的项数。
VirtualCount 获取或设置在使用自定义分页时数据源中的实际项数。
《ASP.NET1200例》<asp:DataList>分页显示图片的更多相关文章
- 《ASP.NET1200例》在DataList里编辑和删除数据
学习内容:如何创建一个支持编辑和删除数据的DataList.增加编辑和删除功能需要在DataList的ItemTemplate和EditItemTemplate里增加合适的控件,创建对应的事件处理,读 ...
- 《ASP.NET1200例》ListView 控件与DataPager控件的结合<二>
ASP.NET使用ListView数据绑定控件和DataPager实现数据分页显示 为什么使用ListView+DataPager的方式实现分页显示? .net提供的诸多数据绑定控件,每一种都有它自己 ...
- 《ASP.NET1200例》ListView 控件与DataPager控件的结合<一>
分页 在前一部分开始时介绍的原 HTML 设计中内含分页和排序,所以根据规范完整实现该网格的任务尚未完成.我们先分页,然后再排序. ListView 控件中的分页通过引入另一个新控件 Data ...
- 《ASP.NET1200例》<ItemTemplate>标签在html里面有什么具体的作用
严格的来说 <ItemTemplate> 在html中无意义,他只是针对诸如 Repeater.DataList.GridView中的一个模板 至于里面的含义,你可以这样想,既然Repea ...
- 《ASP.NET1200例》C#在网页上编写动态时钟
包含Timer类的命名空间有3个 Timer Class (System.Threading) Timer Class (System.Windows.Forms) 一般用于窗体程序 Timer ...
- 《ASP.NET1200例》高亮显示ListView中的数据行并自动切换图片
aspx <script type="text/javascript"> var oldColor; function SetNewColor(Source) { ol ...
- 《ASP.NET1200例》嵌套在DataLisT控件中的其他服务器控件---DropDownList控件的数据绑定
aspx <script type="text/javascript"> function CheckAll(Obj) { var AllObj = document. ...
- 《ASP.NET1200例》ASP.Net 之Datalist数据删除(支持批量)
.aspx <div> <asp:DataList ID="DataList1" runat="server" Width="355 ...
- 《ASP.NET1200例》ListView控件之修改,删除与添加
aspx <body> <form id="form1" runat="server"> <div> <asp:Lis ...
随机推荐
- javascript函数自调用
1. 函数是由事件驱动的或者当它被调用时执行的可重复使用的代码块. 2. 将函数用 “()”括起来, 后面再加一个“()” 3. javascript函数的内置对象arguments对象, 它包 ...
- Could not load resource factory class [Root exception is java.lang.ClassNotFoundException: org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory]
WARNING: Failed to register in JMX: javax.naming.NamingException: Could not load resource factory cl ...
- HYSBZ1036 树链剖分
这题我建了2棵线段树,这样来处理 最值和和值,简单的题目. #include<queue> #include<stack> #include<cmath> #inc ...
- 35.Android之带删除按钮EditText学习
今天实现Android里自定义带删除功能的EditText,效果如下: 当输入内容时,EditText变为带有一个删除功能按钮的编辑框,如图: 实现代码很简单,直接上代码, 布局文件xml: < ...
- 【codevs1200】 NOIP2012—同余方程
codevs.cn/problem/1200/ (题目链接) 题意 求关于 x 的同余方程 ax ≡ 1 (mod b)的最小正整数解. Solution 这道题其实就是求${a~mod~b}$的逆元 ...
- 【poj2226】 Muddy Fields
http://poj.org/problem?id=2226 (题目链接) 题意 给出一个只包含‘.’和‘*’的矩阵,用任意长度的宽为1的木板覆盖所有的‘*’而不覆盖‘.’,木板必须跟矩形的长或宽平行 ...
- 【bzoj1046】 HAOI2007—上升序列
http://www.lydsy.com/JudgeOnline/problem.php?id=1046 (题目链接) 题意 给出一个数列,求数列中长度为L的下标字典序最小的上升子序列. Soluti ...
- Treap实现山寨set
treap插入.删除.查询时间复杂度均为O(logn) treap树中每个节点有两种权值:键值和该节点优先值 如果只看优先值,这棵树又是一个堆 treap有两种平衡方法:左旋&右旋 inser ...
- Maven学习笔记-03-Eclipse下maven项目在Tomcat7和Jetty6中部署调试
现在最新的Eclipse Luna Release 已经内置了Maven插件,这让我们的工作简洁了不少,只要把项目直接导入就可以,不用考虑插件什么的问题,但是导入之后的项目既可以部署在Tomcat也可 ...
- Apple的App Analytics统计平台你必须知道的Q&A整理与翻译
Apple的App Analytics统计平台你必须知道的Q&A整理与翻译 Apple最近在iTunesConnect里最新发布了App Analytics统计平台,提供了现有友盟统计平台和自 ...