最上面为Panel控件,用于显示图像列表,下面有“上页”和“下页”以及可以选择到某一页。
--wap.joymo.cn
代码如下:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Mobile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.MobileControls;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
// 内容来自wap.joymo.cn
// 作者:freemobile
namespace joymo
{
public partial class usercontrol_PicList : System.Web.UI.MobileControls.MobileUserControl
{
public DataTable PicData; // 由调用控件的页面赋值
private int _pageSize = 0;
private int _pageCount = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack && PicData != null)
{
try
{
GetSelectPage(Math.Abs(Convert.ToInt32(Request.QueryString["page"])));
}
catch(Exception ex)
{}
}
}
// 显示相应页数的页面 -- wap.joymo.cn
protected void GetSelectPage(int page)
{
_pageSize = Convert.ToInt32(ConfigurationManager.AppSettings["PicPageSize"]); // 每页的条数
if (PicData != null && PicData.Rows.Count > 0)
{
int itemCount = PicData.Rows.Count;
_pageCount = 0;
if(itemCount%_pageSize != 0)
_pageCount = itemCount / _pageSize + 1;
else
_pageCount = itemCount / _pageSize;
int startID = page * _pageSize;
if (startID >= itemCount)
startID = (_pageCount - 1) * _pageSize;
int endID = startID + _pageSize;
for (int i = startID; i < (itemCount>endID?endID:itemCount); i++)
{
System.Web.UI.MobileControls.Image img = new System.Web.UI.MobileControls.Image();
img.ImageUrl = (string)PicData.Rows[i][0]; // 缩略图片
img.NavigateUrl = (string)PicData.Rows[i][1]; // 实际图片位置
img.BreakAfter = false;
Panel1.Controls.Add(img);
Link linkMemo = new Link();
linkMemo.Text = (string)PicData.Rows[i][2]; // 图片描述
linkMemo.NavigateUrl = (string)PicData.Rows[i][1];
Panel1.Controls.Add(linkMemo);
}
if (page == 0)
{
LinkPre.NavigateUrl = Page.Request.FilePath + "?page=0"; // "上页"链接
LinkNext.NavigateUrl = Page.Request.FilePath + "?page=0"; // "下页"链接
}
else
{
LinkPre.NavigateUrl = Page.Request.FilePath + "?page=" + (page - 1);
LinkNext.NavigateUrl = Page.Request.FilePath + "?page=" + (page + 1);
}
LabPage.Text = "共" + _pageCount + "页->第" + (page + 1) + "页";
}
}
protected void CmdGo_Click(object sender, EventArgs e)
{
try
{
((MobilePage)Page).RedirectToMobilePage(Request.FilePath + "?page=" + Math.Abs(Convert.ToInt32(TextBox1.Text)-1));
}
catch(Exception ex)
{}
}
}
}
最终的执行效果如下: