data list分页显示图片功能的实现:
1. 定义静态变量
private static PhotoTables photos = new PhotoTables(); '存储图片路径列表
'记录所有页和当前页
private static Int32 current_pos = 1;
private static Int32 totalPage;
private static Int32 currPage;
private enum pageAct{down,up};
2.实现翻页函数
//翻页
private void pageTurn(Int32 action)
{
switch (action)
{
case (Int32)pageAct.down:
{
if (currPage == totalPage)
{
pageTurn((Int32)pageAct.up);
return;
}
else
{
currPage += 1;
current_pos += 36;
showPhoto();
}
break;
}
case (Int32)pageAct.up:
{
if (currPage == 1)
{
//pageTurn(pageAct.up);
return;
}
else
{
currPage -= 1;
current_pos -= 36;
showPhoto();
}
break;
}
}
procPage();
}
//计算页数
private void calPage()
{
Int32 rowCount = photos.Count;
Int32 mod;
totalPage = rowCount / 36;
mod = rowCount % 36;
if (mod > 0) totalPage += 1;
current_pos = 1;
currPage = 1;
procPage();
}
3.显示当前页图片函数
//显示当前页图片
private void showPhoto()
{
Int32 i = 1;
Int32 len = 1;
PhotoTables ps = new PhotoTables();
foreach (PhotoTable photo in photos)
{
if (i >= current_pos)
{
len = i - current_pos;
ps.Add(photo);
if (len >= 35)
{
dlPhoto.DataSource = ps;
dlPhoto.DataBind();
//current_pos += len;
return;
}
}
i += 1;
}
dlPhoto.DataSource = ps;
dlPhoto.DataBind();
//current_pos += len;
}