使用DirectoryInfo绑定数据,然后分页的问题。
代码如下,绑定后,如果一次性显示,没有问题,但是如果我把pagesize=2,那么显示就有问题了。每次都只是显示同样的图片。为什么?麻烦通俗直观的解释。谢谢
<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<!DOCTYPE html>
<script runat="server">
void page_load()
{
if(!Page.IsPostBack)
{
DirectoryInfo file = new DirectoryInfo(MapPath("~/14/images"));
ListView1.DataSource = file.GetFiles("*.jpg");
ListView1.DataBind();
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListView ID="ListView1" runat="server">
<LayoutTemplate>
<ol>
<asp:PlaceHolder
ID="itemPlaceholder"
runat="server"
/>
</ol>
<asp:DataPager
ID="aa"
PageSize="10"
runat="server"
>
<Fields>
<asp:NextPreviousPagerField
ShowFirstPageButton="true"
ShowPreviousPageButton="true"
ShowNextPageButton="false"
ShowLastPageButton="false" />
<asp:NumericPagerField />
<asp:NextPreviousPagerField
ShowFirstPagebutton="false"
ShowPreviousPageButton="false"
ShowNextPageButton="true"
ShowLastPageButton="true" />
</Fields>
</asp:DataPager>
</LayoutTemplate>
<ItemTemplate>
<asp:Image
runat="server"
ID="img1"
ImageUrl='<%# Eval("Name","~/14/images/{0}") %>'
Width="500px"
Height="300px"
name="imgA" />
</ItemTemplate>
</asp:ListView>
</div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</form>
</body>
</html>