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>分页显示图片的更多相关文章

  1. 《ASP.NET1200例》在DataList里编辑和删除数据

    学习内容:如何创建一个支持编辑和删除数据的DataList.增加编辑和删除功能需要在DataList的ItemTemplate和EditItemTemplate里增加合适的控件,创建对应的事件处理,读 ...

  2. 《ASP.NET1200例》ListView 控件与DataPager控件的结合<二>

    ASP.NET使用ListView数据绑定控件和DataPager实现数据分页显示 为什么使用ListView+DataPager的方式实现分页显示? .net提供的诸多数据绑定控件,每一种都有它自己 ...

  3. 《ASP.NET1200例》ListView 控件与DataPager控件的结合<一>

    分页     在前一部分开始时介绍的原 HTML 设计中内含分页和排序,所以根据规范完整实现该网格的任务尚未完成.我们先分页,然后再排序. ListView 控件中的分页通过引入另一个新控件 Data ...

  4. 《ASP.NET1200例》<ItemTemplate>标签在html里面有什么具体的作用

    严格的来说 <ItemTemplate> 在html中无意义,他只是针对诸如 Repeater.DataList.GridView中的一个模板 至于里面的含义,你可以这样想,既然Repea ...

  5. 《ASP.NET1200例》C#在网页上编写动态时钟

    包含Timer类的命名空间有3个 Timer Class (System.Threading)‎ Timer Class (System.Windows.Forms)‎ 一般用于窗体程序 Timer  ...

  6. 《ASP.NET1200例》高亮显示ListView中的数据行并自动切换图片

    aspx <script type="text/javascript"> var oldColor; function SetNewColor(Source) { ol ...

  7. 《ASP.NET1200例》嵌套在DataLisT控件中的其他服务器控件---DropDownList控件的数据绑定

    aspx <script type="text/javascript"> function CheckAll(Obj) { var AllObj = document. ...

  8. 《ASP.NET1200例》ASP.Net 之Datalist数据删除(支持批量)

    .aspx <div> <asp:DataList ID="DataList1" runat="server" Width="355 ...

  9. 《ASP.NET1200例》ListView控件之修改,删除与添加

    aspx <body> <form id="form1" runat="server"> <div> <asp:Lis ...

随机推荐

  1. java.lang.NoSuchFieldError: deferredExpression

    处理:遇到这个异常的时候是用jstl标签,是版本问题,由于MyEclipse添加Java EE5,其中自动包括了jstl1.2的版本,lib中又存在一个jstl1.1.2的jar包,把旧版本的删掉就可 ...

  2. new-nav-js

    'use strict';define([ 'jquery'], function($) { var nav = { init : function() { $("#burger-menu& ...

  3. navjs

    'use strict';define([ 'jquery'], function($) { var nav = { init : function() { $("#burger-menu& ...

  4. G-nav-04

    'use strict';define([ 'jquery'], function($) { var nav = { init : function() { $("#burger-menu& ...

  5. 【bzoj1013】 JSOI2008—球形空间产生器sphere

    www.lydsy.com/JudgeOnline/problem.php?id=1013 (题目链接) 题意 有一个n维的球体,给出球上n+1个点,求出圆心. Solution 题中给出了对于n维空 ...

  6. 【bzoj1179】 Apio2009—Atm

    www.lydsy.com/JudgeOnline/problem.php?id=1179 (题目链接) 题意 给出一张有向图,每个节点有点权.标记一些点,找出一条路径,可以重复经过一条边,使得总点权 ...

  7. [IOS UIScrollView+PageControl]信息展示横幅

    ScrollViewController.h #import <UIKit/UIKit.h> @interface ScrollViewController : UIViewControl ...

  8. this的使用

    1.使用this调用本类中的属性 class Person{ private String name; private int age; public Person(String name,int a ...

  9. HTTPS 协议降级攻击原理

    0x00 HTTPS 在传统流行的web服务中,由于http协议没有对数据包进行加密,导致http协议下的网络包是明文传输,所以只要攻击者拦截到http协议下的数据包,就能直接窥探这些网络包的数据. ...

  10. Nutch2.x 演示抓取第一个网站

    http://www.micmiu.com/opensource/nutch/nutch2x-crawl-first-website/?utm_source=tuicool&utm_mediu ...