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. web服务器

    1.打破信息孤岛,实现信息的集成 2.配置文件  web.xml          定义自己的服务器应该要哪些功能! 3.tomcat 是一个servlet容器,一个web服务器. 部署:将web应用 ...

  2. iOS7(iPhone4)button不能改变button的title

    最近整了个高端的iPhone4测试机,系统是iOS7.1,测出一个问题,两个button,第二个的enable为NO,点击第一个button,第二个的title改变,然而在iPhone4上并不能运行, ...

  3. CSS和字符串实现三角形

    听说是百度校招的题目,就写了一下 <!doctype html> <html> <head> <meta charset="utf-8"& ...

  4. UVA 540 stl

    Queues and Priority Queues are data structures which are known to most computer scientists. The Team ...

  5. Spring对Hibernate的session生效期(事物提交管理)介绍

    在Hibernate中我们每次进行一个操作的的时候我们都是要先开启事务,然后进行数据操作,然后提交事务,关闭事务,这样做的原因是因为Hibernate默认的事务自动提交是false,它是需要人为的手动 ...

  6. Java基础-常量,变量,成员变量,局部变量

    在java中,数据是以常量和变量两种方法形式进行存储和表示的(实际上,所有程序的数据都是这两种形式). 变量 变量代表程序的状态.程序通过改变变量的值来改变整个程序的状态,或者说得更大一些,也就是实现 ...

  7. Windows Server 2008系统如何取消登录时要按Ctrl+Alt+Delete组合键

    1.点桌面任务栏的“开始-->运行”在弹出的窗口中输入gpedit.msc . 2.输入gpedit.msc后,点击确定即打开了组策略编辑器.在组策略编辑器的左框内依次序展开(点前面的“+”号) ...

  8. 思维导图XMiand

    XMiand: 异常强大的国产思维导图工具,还能将图同步到服务器上.做思维导图和头脑风暴必备软件,还能转换绘制鱼骨图.二维图.树形图.逻辑图.组织结构图.

  9. Putty远程登录VMware虚拟机Linux(Ubuntu)

    安装SSH服务 Ubuntu默认并没有安装ssh服务,如果通过ssh链接ubuntu,需要自己手动安装ssh-server.判断是否安装ssh服务,可以通过如下命令进行: www.linuxidc.c ...

  10. sourceinsight安装记录

    sourceinsight安装记录 此文章为本人使用sourceinsight一个星期之后的相关设置步骤记录和经验记录,以备以后查验,网上的相关资料都也较为完善,但是对于新手还是有一定困难的,所以在这 ...