vb.net listview 分页

如题我做了一个窗体里面有个listview控件,我现在已经连接数据库成功显示。但是我想实现分页效果。代码应该怎么写呢。答好再加分... 如题
我做了一个窗体里面有个listview控件,我现在已经连接数据库成功显示。
但是我想实现分页效果。代码应该怎么写呢。

答好再加分
展开
 我来答
lncgliu
2009-03-03 · TA获得超过472个赞
知道答主
回答量:102
采纳率:0%
帮助的人:0
展开全部
用pageDataSource类
与DataSource用法差不多

由于DataList本身没有带分页功能,pageDateSource祢补了这个不足,你可以当作DateSource来使用,没有太大区别

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;

public partial class _Default : System.Web.UI.Page
{
SqlHelper MySqlHelper = new SqlHelper(); // 我写的数据库操作方法集,创建一个实例
Operation MyOperation = new Operation(); // 我写的网站通用处理方法集,创建一个实例
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GbookData();
lb_count.Text = MySqlHelper.MyScalar("SELECT COUNT(*) FROM BBS WHERE BBS_IsDisplay = '1'"); // 记录条数
}
}
protected void GbookData() // 分页程序代码
{
string strURL = Request.RawUrl;
int intPage = 1;
PagedDataSource MyPager = new PagedDataSource();
MyPager.DataSource = MySqlHelper.MyDS("SELECT * FROM BBS WHERE BBS_IsDisplay = '1' ORDER BY BBS_ID DESC").Tables["MyTable"].DefaultView;
MyPager.PageSize = 9;
MyPager.AllowPaging = true;
hpl_first.Enabled = true;
hpl_up.Enabled = true;
hpl_down.Enabled = true;
hpl_end.Enabled = true;
if (strURL.Contains("/Page/"))
{
string strPage = strURL.Substring(strURL.LastIndexOf("/Page/") + 6);
if (strURL.Substring(strURL.LastIndexOf("/")) == "/")
{
Response.Redirect("NoAccess.htm");
}
if (Regex.IsMatch(strPage, "\\d"))
{
int thisPage;
try
{
thisPage = Convert.ToInt32(strURL.Substring(strURL.LastIndexOf("/Page/") + 6));
if (thisPage < 1 || thisPage > MyPager.PageCount)
{
Response.Redirect("NoAccess.htm");
}
else
{
intPage = thisPage;
}
}
catch
{
Response.Redirect("NoAccess.htm");
}
}
else
{
Response.Redirect("NoAccess.htm");
}
}
hpl_first.NavigateUrl = "~/GuestBook/Page/1";
hpl_up.NavigateUrl = "~/GuestBook/Page/" + (intPage - 1).ToString();
hpl_down.NavigateUrl = "~/GuestBook/Page/" + (intPage + 1).ToString();
hpl_end.NavigateUrl = "~/GuestBook/Page/" + MyPager.PageCount;
MyPager.CurrentPageIndex = intPage - 1;
Repeater_1.DataSource = MyPager;
Repeater_1.DataBind();
if (MyPager.IsFirstPage)
{
hpl_first.Enabled = false;
hpl_up.Enabled = false;
}
if (MyPager.IsLastPage)
{
hpl_down.Enabled = false;
hpl_end.Enabled = false;
}
lb_thispage.Text = intPage.ToString(); // 当前页码
lb_totalpage.Text = MyPager.PageCount.ToString(); // 总页数
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式