《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 ...
随机推荐
- 用 Docker 快速配置前端开发环境
来源于:http://dockone.io/article/1714 今天是你入职第一天. 你起了个大早,洗漱干净带着材料去入职. 签了合同,领了机器,坐到工位,泡一杯袋装红茶,按下开机键,输入密码, ...
- java Thread编程(三) 同步的两种不同实现方式
1,创建需要同步的对象(方式一) package concurrency; public class Bank { private double amount; public Bank(double ...
- sql-where
查询表时不一定每一次都要将表格内的资料都完全抓出.在许多时候,我们会需要选择性地抓资料.就我们的例子来说,我们可能只要抓出营业额超过 $1,000 的资料. 要做到这一点,需要用到 WHERE 这个指 ...
- 【CodeForces 602A】C - 特别水的题3-Two Bases
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102271#problem/C Description After seeing the ...
- html+Ajax和JSP的比较
1.有人说JSP会泄露源码(可能会有一些代码痕迹,但肯定没啥大事)2.又说,Ajax是为了分离前后台,让控制部分在前台处理,降低代码耦合度,后台只相当于服务. 3.能够让前台移植,降低后期维护成本.纯 ...
- oracle基本语句
ALTER TABLE SCOTT.TEST RENAME TO TEST1--修改表名 ALTER TABLE SCOTT.TEST RENAME COLUMN NAME TO NAME1 --修改 ...
- springMVC实现防止重复提交
参考文档:http://my.oschina.net/mushui/blog/143397
- BZOJ4590 自动刷题机
Description 曾经发明了信号增幅仪的发明家SHTSC又公开了他的新发明:自动刷题机--一种可以自动AC题目的神秘装置.自动 刷题机刷题的方式非常简单:首先会瞬间得出题目的正确做法,然后开始写 ...
- BZOJ2456 mode
Description 给你一个n个数的数列,其中某个数出现了超过n div 2次即众数,请你找出那个数. Input 第1行一个正整数n. 第2行n个正整数用空格隔开. Output 一行一个正整数 ...
- CF Gym 100685A Ariel
传送门 A. Ariel time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...