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. Windows Office key 持续更新地址

    微软 Windows  Office 系列序列号,每日都有更新,上面显示的基本都可用,包括MAK及Retail Key. Windows 10   http://textuploader.com/52 ...

  2. ssh scp ssh-copy-id 非22端口的操作方法

    (1)首先我们来看一下ssh-copy-id的非22端口的操作方法 ssh-copy-id -i  ~/.ssh/id_rsa.pub "-p 10056 wwwad@192.168.20. ...

  3. BZOJ SCOI2005骑士精神

    裸IDA*,ans从1到15循环来限制搜索深度. #include<cstdio> #include<cstring> #include<algorithm> us ...

  4. 左偏树(DP)问题

    问题:A straight dirt road connects two fields on FJ's farm, but it changes elevation more than FJ woul ...

  5. .net 代码风格规范

    声明:内容非原创,转自张子阳博客. 对于为什么是转载,唯一原因就是这东西居然比我整理的好,直接用得了. 1. C# 代码风格要求 1.1注释 类型.属性.事件.方法.方法参数,根据需要添加注释. 如果 ...

  6. Linux cscope命令

    一.简介 Cscope 是一款开源免费的 C/C++浏览工具,自带一个基于文本的用户界面,通过cscope可以很方便地找到某个函数或变量的定义位置.被调用的位置等信息.Cscope对 C /C++支持 ...

  7. 修改myeclipse 新建JSP文件时的默认模板

    MyEclipse中构造新的jsp模板(原创) 首先随便打开一个jsp页,在网页中单击右键选择:preferences 打开后如图所示,找到jsp template选项. 选择new,在弹出的提示框, ...

  8. NC反弹CMDSHELL提权总结

    Server-U等都不可以用的情况下.   一般都可思考用此方法不过这种方法, 只要对方装了防火墙, 或是屏蔽掉了除常用的那几个端口外的所有端口…   那么这种方法也失效了…. 1:通过shell将上 ...

  9. 一机双mysql的安装和启动注意事项目

    ./configure --prefix=/usr/local/mysql5.1/ --with-mysqld-user=mysql --sysconfdir=/usr/local/mysql5.1/ ...

  10. TreeSet里面放对象,如果同时放入了父类和子类的实例对象,那比较时使用的是父类的compareTo方法,还是使用的子类的compareTo方法,还是抛异常!

    /** * * @author ocq */ class Parent implements Comparable { private int age = 0; public Parent(int a ...