asp.net自定义分页控件
用户控件代码(部分):publicvoidDisplay()//根据条件显示商品信息{PagedDataSourcepds=newPagedDataSource();pd...
用户控件代码(部分):
public void Display()//根据条件显示商品信息
{
PagedDataSource pds = new PagedDataSource();
pds.AllowPaging = true;
pds.DataSource = dt.DefaultView;
pds.PageSize = count;
pds.CurrentPageIndex = Convert.ToInt32(lblNowPage.Text) - 1;
SetEnalble(pds);
rep.DataSource = pds;
rep.DataBind();
lblCountPage.Text = pds.PageCount.ToString();
}
public DataTable dt = null; //指定的数据源
public Repeater rep = null; //指定repeater
protected void txtPage_TextChanged(object sender, EventArgs e) //页码跳转事件
{
lblNowPage.Text = Convert.ToInt32(txtPage.Text.Trim()).ToString();
Display();
}
protected void lnkFirst_Click(object sender, EventArgs e)
{
lblNowPage.Text = "1";
Display();
}
protected void lnkPre_Click(object sender, EventArgs e)
{
lblNowPage.Text = (Convert.ToInt32(lblNowPage.Text) - 1).ToString();
Display();
}
protected void lnkNext_Click(object sender, EventArgs e)
{
lblNowPage.Text = (Convert.ToInt32(lblNowPage.Text) + 1).ToString();
Display();
}
protected void lnkLast_Click(object sender, EventArgs e)
{
lblNowPage.Text = lblCountPage.Text;
Display();
}
}
调用页:
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = productBll.GetTable(""); //通过数据访问层得到DataTable对象
PageControl1.dt = dt;
PageControl1.rep = repProduct;
PageControl1.Display();
}
还有些代码太多我就不贴了 以前我是把所有数据查出来进行的分页,这样性能可能不怎么样
现在我考虑的问题就是select top 的形式 但是怎么在用户控件翻页的时候,调用页根据当前页去数据库获取数据而不是一次性把数据获取完再进行分页
我想过用viewstate和反射 不过好像viewstate在用户控件里面定义的在内容页得不到,反射又增加了调用页的代码量 我就是要尽最大去减少调用页的代码量
请各位贴点源码,给点思路 展开
public void Display()//根据条件显示商品信息
{
PagedDataSource pds = new PagedDataSource();
pds.AllowPaging = true;
pds.DataSource = dt.DefaultView;
pds.PageSize = count;
pds.CurrentPageIndex = Convert.ToInt32(lblNowPage.Text) - 1;
SetEnalble(pds);
rep.DataSource = pds;
rep.DataBind();
lblCountPage.Text = pds.PageCount.ToString();
}
public DataTable dt = null; //指定的数据源
public Repeater rep = null; //指定repeater
protected void txtPage_TextChanged(object sender, EventArgs e) //页码跳转事件
{
lblNowPage.Text = Convert.ToInt32(txtPage.Text.Trim()).ToString();
Display();
}
protected void lnkFirst_Click(object sender, EventArgs e)
{
lblNowPage.Text = "1";
Display();
}
protected void lnkPre_Click(object sender, EventArgs e)
{
lblNowPage.Text = (Convert.ToInt32(lblNowPage.Text) - 1).ToString();
Display();
}
protected void lnkNext_Click(object sender, EventArgs e)
{
lblNowPage.Text = (Convert.ToInt32(lblNowPage.Text) + 1).ToString();
Display();
}
protected void lnkLast_Click(object sender, EventArgs e)
{
lblNowPage.Text = lblCountPage.Text;
Display();
}
}
调用页:
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = productBll.GetTable(""); //通过数据访问层得到DataTable对象
PageControl1.dt = dt;
PageControl1.rep = repProduct;
PageControl1.Display();
}
还有些代码太多我就不贴了 以前我是把所有数据查出来进行的分页,这样性能可能不怎么样
现在我考虑的问题就是select top 的形式 但是怎么在用户控件翻页的时候,调用页根据当前页去数据库获取数据而不是一次性把数据获取完再进行分页
我想过用viewstate和反射 不过好像viewstate在用户控件里面定义的在内容页得不到,反射又增加了调用页的代码量 我就是要尽最大去减少调用页的代码量
请各位贴点源码,给点思路 展开
4个回答
展开全部
baidu hi我给你一个我原来写的用户控件 很简单,看看应该就明白了,
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
int pageSize = 4; //每页显示行数
int nMax = 0; //总记录数
int pageCount = 0; //页数=总记录数/每页显示行数
int pageCurrent = 0; //当前页号
int nCurrent = 0; //当前记录行
DataSet ds = new DataSet();
DataTable dtInfo = new DataTable();
private void init()
{
if (dtInfo.Rows.Count == 0)
{
toolStripTextBox1.Text = "0";
toolStripLabel3.Text = "/ 0";
txtCurrentPage.Text = " 总页数:1";
lblPageCount.Text = " 总页数:1";
}
else
{
InitDataSet(pageSize);
}
}
private void InitDataSet(int pages)
{
pageSize = pages; //设置页面行数
nMax = dtInfo.Rows.Count;
pageCount = (nMax / pageSize); //计算出总页数
if ((nMax % pageSize) > 0) pageCount++;
pageCurrent = 1; //当前页数从1开始
nCurrent = 0; //当前记录数从0开始
LoadData();
}
private void LoadData()
{
dataGridView_Area.Refresh();
int nStartPos = 0; //当前页面开始记录行
int nEndPos = 0; //当前页面结束记录行
DataTable dtTemp = dtInfo.Clone(); //克隆DataTable结构框架
if (pageCurrent == pageCount)
nEndPos = nMax;
else
nEndPos = pageSize * pageCurrent;
nStartPos = nCurrent;
lblPageCount.Text = " 总页数:" + pageCount.ToString();
txtCurrentPage.Text = " 当前页数:" + Convert.ToString(pageCurrent);
//从元数据源复制记录行
for (int i = nStartPos; i < nEndPos; i++)
{
dtTemp.ImportRow(dtInfo.Rows[i]);
nCurrent++;
}
bdsInfo.DataSource = dtTemp;
bindingNavigator1.BindingSource = bdsInfo;
dataGridView_Area.DataSource = bdsInfo;
}
private void bindingNavigator1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
if (e.ClickedItem == bindingNavigatorDeleteItem)
{
this.Close();
}
if (e.ClickedItem == up)
{
pageCurrent--;
if (pageCurrent <= 0)
{
pageCurrent++;
//MessageBox.Show("已经是第一页,请”查看!");
return;
}
else
{
nCurrent = pageSize * (pageCurrent - 1);
}
LoadData();
}
if (e.ClickedItem == down)
{
pageCurrent++;
if (pageCurrent > pageCount)
{
pageCurrent--;
//MessageBox.Show("已经是最后一页,请”查看!");
return;
}
else
{
nCurrent = pageSize * (pageCurrent - 1);
}
LoadData();
}
}
private void toolStripComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
pageSize = int.Parse(this.toolStripComboBox.Text.Trim());
init();
}
这个是利用VS自带的分页控件,你将你的数据源绑定到上面就可以了。
int nMax = 0; //总记录数
int pageCount = 0; //页数=总记录数/每页显示行数
int pageCurrent = 0; //当前页号
int nCurrent = 0; //当前记录行
DataSet ds = new DataSet();
DataTable dtInfo = new DataTable();
private void init()
{
if (dtInfo.Rows.Count == 0)
{
toolStripTextBox1.Text = "0";
toolStripLabel3.Text = "/ 0";
txtCurrentPage.Text = " 总页数:1";
lblPageCount.Text = " 总页数:1";
}
else
{
InitDataSet(pageSize);
}
}
private void InitDataSet(int pages)
{
pageSize = pages; //设置页面行数
nMax = dtInfo.Rows.Count;
pageCount = (nMax / pageSize); //计算出总页数
if ((nMax % pageSize) > 0) pageCount++;
pageCurrent = 1; //当前页数从1开始
nCurrent = 0; //当前记录数从0开始
LoadData();
}
private void LoadData()
{
dataGridView_Area.Refresh();
int nStartPos = 0; //当前页面开始记录行
int nEndPos = 0; //当前页面结束记录行
DataTable dtTemp = dtInfo.Clone(); //克隆DataTable结构框架
if (pageCurrent == pageCount)
nEndPos = nMax;
else
nEndPos = pageSize * pageCurrent;
nStartPos = nCurrent;
lblPageCount.Text = " 总页数:" + pageCount.ToString();
txtCurrentPage.Text = " 当前页数:" + Convert.ToString(pageCurrent);
//从元数据源复制记录行
for (int i = nStartPos; i < nEndPos; i++)
{
dtTemp.ImportRow(dtInfo.Rows[i]);
nCurrent++;
}
bdsInfo.DataSource = dtTemp;
bindingNavigator1.BindingSource = bdsInfo;
dataGridView_Area.DataSource = bdsInfo;
}
private void bindingNavigator1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
if (e.ClickedItem == bindingNavigatorDeleteItem)
{
this.Close();
}
if (e.ClickedItem == up)
{
pageCurrent--;
if (pageCurrent <= 0)
{
pageCurrent++;
//MessageBox.Show("已经是第一页,请”查看!");
return;
}
else
{
nCurrent = pageSize * (pageCurrent - 1);
}
LoadData();
}
if (e.ClickedItem == down)
{
pageCurrent++;
if (pageCurrent > pageCount)
{
pageCurrent--;
//MessageBox.Show("已经是最后一页,请”查看!");
return;
}
else
{
nCurrent = pageSize * (pageCurrent - 1);
}
LoadData();
}
}
private void toolStripComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
pageSize = int.Parse(this.toolStripComboBox.Text.Trim());
init();
}
这个是利用VS自带的分页控件,你将你的数据源绑定到上面就可以了。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
自己写 一个分页 控件
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
.NET控件下载地址大全:
CuteEditor 6.0 在线HTML编辑器的领航者
ComponentArt.Charting.WebChart.dll
ComponentArt.Web.UI 2007.2源代码+实例+DLL
ComponentArt.WebUI.2007.1破解DLL
ComponentArt.WebUI.2007.1源代码
ComponentArt.Web.UI.2006.2
ComponentArt.Web.UI.2006.2源代码
ComponentArt.Web.UI.2006.1
Infragistics NetAdvantage for ASP.NET 2007 Vol 2
Infragistics NetAdvantage AppStylist 2007 Vol 2
Infragistics TestAdvantage WinForms 2007 For CLR2
Infragistics TestAdvantage WinForms 2007 for CLR1.x
Infragistics NetAdvantage for Windows Forms 2007 Vol 2
Infragistics NetAdvantage 2007 for WPF
Infragistics NetAdvantage 2006 Vol2 CLR1.x
Infragistics NetAdvantage 2006 Vol2 for CLR2
Infragistics NetAdvantage 2006 Vol2 CLR1.x
ComponentOne Studio 2007 v1.5 for ASP.NET 2.0
ComponentOne Studio 2007 v1.5 for ASP.NET 1.x
ComponentOne Studio 2006 v2 for ASP.NET 2.0
ComponentOne Studio 2006 v2 for ASP.NET 1.x
ComponentOne Studio for Mobile Devices 2007 v1.5 CLR1x
ComponentOne Studio for Mobile Devices 2006 v2 CLR2
ComponentOne Studio for Mobile Devices 2006 v2 CLR1.x
ComponentOne Studio 2007 v1.5 for .NET CLR2
ComponentOne Studio 2007 v1.5 for .NET CLR1.x
ComponentOne Studio for .NET 2006 v2 CLR2
ComponentOne Studio for .NET 2006 v2 CLR1.x
ComponentOne Studio for ActiveX 2007 v1.5
ComponentOne Studio for ActiveX 2006 v2 CLR2
ComponentOne Studio for ActiveX 2006 v2 CLR1.x
Telerik RadWindow for ASP.NET 2.0 v1.8.2.0
Telerik RadUpload for ASP.NET 2.0 v2.3.2.0
Telerik RadTreeView for ASP.NET 2.0 v6.2.2.0
Telerik RadTabStrip for ASP.NET 2.0 v3.5.2.0
Telerik RadToolbar for ASP.NET 2.0 v1.5.2.0
Telerik RadSplitter for ASP.NET 2.0 v1.2.2.1
Telerik RadSpell for ASP.NET 2.0 v3.1.2.0
Telerik RadRotator for ASP.NET 2.0 v2.6.2.0
Telerik RadPanelbar for ASP.NET 2.0 v4.2.2.0
Telerik RadMenu for ASP.NET 2.0 v4.2.2.0
Telerik RadInput for ASP.NET 2.0 v2.0.2.0
Telerik RadGrid for ASP.NET 2.0 v4.6.2.0
Telerik RadEditor for ASP.NET 2.0 v7.1.2.0
Telerik RadComboBox for ASP.NET 2.0 v2.7.2.0
Telerik RadDock for ASP.NET 2.0 v1.8.2.0
Telerik RadChart for ASP.NET 2.0 v3.2.1.0
Telerik RadCalendar for ASP.NET 2.0 v2.1.2.0
Telerik RadAjax for ASP.NET 2.0 v1.7.2.0
telerik r.a.d.upload
telerik r.a.d.window
telerik r.a.d ToolBar
telerik r.a.d.Chart
telerik r.a.d.combobox
DotNetBar for VS2005 6.8.0.1
DotnetCharting 4.3破解DLL
DotNET Charting WebForms
dotnetCharting.WinForms
TeeChart for .NET 3.2.2763.26084 完美DLL
TeeChart for .NET 3.2.2699.17379 完美DLL
Godiagram Web 2.6.2 for .NET 2.0
Godiagram Win 2.6.2 for .NET 2.0
DevExpress 7.3.4 完美破解DLL
Dxperience 7.3.5 完美破解DLL
DevExpress.LocalizationCHS.Dll
NickLee.Web.UI
SolpartWebControls
AspNetPager 6.0 for ASP.NET 1.x 自定义分页控件
AspNetPager 6.0 for ASP.NET 2.0 自定义分页控件
数据操作类 Socut.Data.dll for .NET 2.0 v3.1
数据操作类 Socut.Data.dll for .NET 1.x v3.1
Developer Express for .NET v7.3.5.0全套完美无限制版
CuteEditor 6.0 在线HTML编辑器的领航者
ComponentArt.Charting.WebChart.dll
ComponentArt.Web.UI 2007.2源代码+实例+DLL
ComponentArt.WebUI.2007.1破解DLL
ComponentArt.WebUI.2007.1源代码
ComponentArt.Web.UI.2006.2
ComponentArt.Web.UI.2006.2源代码
ComponentArt.Web.UI.2006.1
Infragistics NetAdvantage for ASP.NET 2007 Vol 2
Infragistics NetAdvantage AppStylist 2007 Vol 2
Infragistics TestAdvantage WinForms 2007 For CLR2
Infragistics TestAdvantage WinForms 2007 for CLR1.x
Infragistics NetAdvantage for Windows Forms 2007 Vol 2
Infragistics NetAdvantage 2007 for WPF
Infragistics NetAdvantage 2006 Vol2 CLR1.x
Infragistics NetAdvantage 2006 Vol2 for CLR2
Infragistics NetAdvantage 2006 Vol2 CLR1.x
ComponentOne Studio 2007 v1.5 for ASP.NET 2.0
ComponentOne Studio 2007 v1.5 for ASP.NET 1.x
ComponentOne Studio 2006 v2 for ASP.NET 2.0
ComponentOne Studio 2006 v2 for ASP.NET 1.x
ComponentOne Studio for Mobile Devices 2007 v1.5 CLR1x
ComponentOne Studio for Mobile Devices 2006 v2 CLR2
ComponentOne Studio for Mobile Devices 2006 v2 CLR1.x
ComponentOne Studio 2007 v1.5 for .NET CLR2
ComponentOne Studio 2007 v1.5 for .NET CLR1.x
ComponentOne Studio for .NET 2006 v2 CLR2
ComponentOne Studio for .NET 2006 v2 CLR1.x
ComponentOne Studio for ActiveX 2007 v1.5
ComponentOne Studio for ActiveX 2006 v2 CLR2
ComponentOne Studio for ActiveX 2006 v2 CLR1.x
Telerik RadWindow for ASP.NET 2.0 v1.8.2.0
Telerik RadUpload for ASP.NET 2.0 v2.3.2.0
Telerik RadTreeView for ASP.NET 2.0 v6.2.2.0
Telerik RadTabStrip for ASP.NET 2.0 v3.5.2.0
Telerik RadToolbar for ASP.NET 2.0 v1.5.2.0
Telerik RadSplitter for ASP.NET 2.0 v1.2.2.1
Telerik RadSpell for ASP.NET 2.0 v3.1.2.0
Telerik RadRotator for ASP.NET 2.0 v2.6.2.0
Telerik RadPanelbar for ASP.NET 2.0 v4.2.2.0
Telerik RadMenu for ASP.NET 2.0 v4.2.2.0
Telerik RadInput for ASP.NET 2.0 v2.0.2.0
Telerik RadGrid for ASP.NET 2.0 v4.6.2.0
Telerik RadEditor for ASP.NET 2.0 v7.1.2.0
Telerik RadComboBox for ASP.NET 2.0 v2.7.2.0
Telerik RadDock for ASP.NET 2.0 v1.8.2.0
Telerik RadChart for ASP.NET 2.0 v3.2.1.0
Telerik RadCalendar for ASP.NET 2.0 v2.1.2.0
Telerik RadAjax for ASP.NET 2.0 v1.7.2.0
telerik r.a.d.upload
telerik r.a.d.window
telerik r.a.d ToolBar
telerik r.a.d.Chart
telerik r.a.d.combobox
DotNetBar for VS2005 6.8.0.1
DotnetCharting 4.3破解DLL
DotNET Charting WebForms
dotnetCharting.WinForms
TeeChart for .NET 3.2.2763.26084 完美DLL
TeeChart for .NET 3.2.2699.17379 完美DLL
Godiagram Web 2.6.2 for .NET 2.0
Godiagram Win 2.6.2 for .NET 2.0
DevExpress 7.3.4 完美破解DLL
Dxperience 7.3.5 完美破解DLL
DevExpress.LocalizationCHS.Dll
NickLee.Web.UI
SolpartWebControls
AspNetPager 6.0 for ASP.NET 1.x 自定义分页控件
AspNetPager 6.0 for ASP.NET 2.0 自定义分页控件
数据操作类 Socut.Data.dll for .NET 2.0 v3.1
数据操作类 Socut.Data.dll for .NET 1.x v3.1
Developer Express for .NET v7.3.5.0全套完美无限制版
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询