谁能讲述一下asp.net pager 控件的简单使用方法?
我用的是sqlserver2005devoloperedition。vs2005,。netframework2.0.。。。<addkey="dsn"value="Data...
我用的是sql server 2005 devoloper edition。vs 2005,。net framework2.0.。。。
<add key="dsn" value="Data Source=(local);UID=sa;PWD=**;DATABASE=LMS"/> 用这个格式连接数据库的。
想用asp.net pager 控件把数据库表格的内容分页显示出来。表的内容可以随便。AspNetPager.dll,UrlRewritingNet.UrlRewriter.dll 我已经下载好了。
比方说表里的内容是别人的留言信息,我把留言者的名称用label,留言的内容用table,日期用别的什么的,分页的部分有第一页,下一页,上一页,最后一页等语句来写。地址像http://../page_1.aspx,/page_2.aspx重写。怎样实现啊?给个自己编写的最简单的实例多加分,qq:764665868.或者msn:almas_chn@hotmail.com。在线等待!急!!答案满足加分加到大侠满足位置!先谢了
能不能给个具体点的实例啊?拜托。。。。。 aspx 怎么写 cs 怎么写啊? 展开
<add key="dsn" value="Data Source=(local);UID=sa;PWD=**;DATABASE=LMS"/> 用这个格式连接数据库的。
想用asp.net pager 控件把数据库表格的内容分页显示出来。表的内容可以随便。AspNetPager.dll,UrlRewritingNet.UrlRewriter.dll 我已经下载好了。
比方说表里的内容是别人的留言信息,我把留言者的名称用label,留言的内容用table,日期用别的什么的,分页的部分有第一页,下一页,上一页,最后一页等语句来写。地址像http://../page_1.aspx,/page_2.aspx重写。怎样实现啊?给个自己编写的最简单的实例多加分,qq:764665868.或者msn:almas_chn@hotmail.com。在线等待!急!!答案满足加分加到大侠满足位置!先谢了
能不能给个具体点的实例啊?拜托。。。。。 aspx 怎么写 cs 怎么写啊? 展开
展开全部
在数据库中写存储过程
第一个获取数据
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[sp_GetRows]
@tblName varchar(255), -- 表名
@fldName varchar(1000), -- 所要提取的字段名
@OrderByfldName varchar(255), -- 排序所依据的字段名
@OrderType int = 0, -- 设置排序类型,默认0为升序,非0为降序
@PageSize int = 10, -- 每页显示的记录数
@PageIndex int = 1, -- 页码
@strWhere varchar(1000)='1=1' -- 查询条件 (注意: 不要加 where)
AS
declare @strSQL varchar(6000) -- 主语句
if @OrderType != 0 begin
set @strSQL='SELECT * FROM (SELECT ROW_NUMBER() OVER(order by '+@OrderByfldName+' desc) AS pos,'+@fldName+' FROM ['+@tblName+'] where '+@strWhere+') AS sp WHERE pos BETWEEN '+str((@PageIndex-1)*@PageSize+1)+' AND '+str(@PageIndex*@PageSize)
end
else begin
set @strSQL='SELECT * FROM (SELECT ROW_NUMBER() OVER(order by '+@OrderByfldName+' asc) AS pos,'+@fldName+' FROM ['+@tblName+'] where '+@strWhere+') AS sp WHERE pos BETWEEN '+str((@PageIndex-1)*@PageSize+1)+' AND '+str(@PageIndex*@PageSize)
end
--print @strSQL
exec (@strSQL)
第二个 获取数据行
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
--获取数据表记录数量的存储过程
ALTER proc [dbo].[sp_GetRowsCount]
@tblName varchar(255), -- 表名
@strWhere varchar(1000) = '1=1' -- 查询条件 (注意: 不要加 where)
as
declare @strSql varchar(6000) --查询语句
set @strSql='select count(*) as Total from ['+@tblName+'] where '+@strWhere
--print @strSql
exec (@strSql)
然后再调用这两个存储过程
在前台中这样写:
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %> 注册一下
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" AlwaysShow="True"
CssClass="paginator" CurrentPageButtonClass="cpb"
PrevPageText="上一页"
LastPageText="末页" FirstPageText="首页" NextPageText="下一页"
NumericButtonCount="3" onpagechanged="AspNetPager1_PageChanged1">
</webdiyer:AspNetPager>
后台这样写:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BLL.Common com = new BLL.Common();
this.AspNetPager1.RecordCount = com.GetRowsCount("***");
this.AspNetPager1.PageSize = 5;
this.databind(this.txt_select.Text.Trim());
}
}
public void databind(string str)
{
int currPageIndex = this.AspNetPager1.CurrentPageIndex;
BLL.Common com = new BLL.Common();
DataTable dt = com.GetRows("***", "*", "djid", 0, 5, currPageIndex, "**’” like '%" + str + "%'");
this.gw_select.DataSource = dt;
this.gw_select.DataKeyNames = new string[] { "***" };
this.gw_select.DataBind();
}
第一个获取数据
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[sp_GetRows]
@tblName varchar(255), -- 表名
@fldName varchar(1000), -- 所要提取的字段名
@OrderByfldName varchar(255), -- 排序所依据的字段名
@OrderType int = 0, -- 设置排序类型,默认0为升序,非0为降序
@PageSize int = 10, -- 每页显示的记录数
@PageIndex int = 1, -- 页码
@strWhere varchar(1000)='1=1' -- 查询条件 (注意: 不要加 where)
AS
declare @strSQL varchar(6000) -- 主语句
if @OrderType != 0 begin
set @strSQL='SELECT * FROM (SELECT ROW_NUMBER() OVER(order by '+@OrderByfldName+' desc) AS pos,'+@fldName+' FROM ['+@tblName+'] where '+@strWhere+') AS sp WHERE pos BETWEEN '+str((@PageIndex-1)*@PageSize+1)+' AND '+str(@PageIndex*@PageSize)
end
else begin
set @strSQL='SELECT * FROM (SELECT ROW_NUMBER() OVER(order by '+@OrderByfldName+' asc) AS pos,'+@fldName+' FROM ['+@tblName+'] where '+@strWhere+') AS sp WHERE pos BETWEEN '+str((@PageIndex-1)*@PageSize+1)+' AND '+str(@PageIndex*@PageSize)
end
--print @strSQL
exec (@strSQL)
第二个 获取数据行
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
--获取数据表记录数量的存储过程
ALTER proc [dbo].[sp_GetRowsCount]
@tblName varchar(255), -- 表名
@strWhere varchar(1000) = '1=1' -- 查询条件 (注意: 不要加 where)
as
declare @strSql varchar(6000) --查询语句
set @strSql='select count(*) as Total from ['+@tblName+'] where '+@strWhere
--print @strSql
exec (@strSql)
然后再调用这两个存储过程
在前台中这样写:
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %> 注册一下
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" AlwaysShow="True"
CssClass="paginator" CurrentPageButtonClass="cpb"
PrevPageText="上一页"
LastPageText="末页" FirstPageText="首页" NextPageText="下一页"
NumericButtonCount="3" onpagechanged="AspNetPager1_PageChanged1">
</webdiyer:AspNetPager>
后台这样写:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BLL.Common com = new BLL.Common();
this.AspNetPager1.RecordCount = com.GetRowsCount("***");
this.AspNetPager1.PageSize = 5;
this.databind(this.txt_select.Text.Trim());
}
}
public void databind(string str)
{
int currPageIndex = this.AspNetPager1.CurrentPageIndex;
BLL.Common com = new BLL.Common();
DataTable dt = com.GetRows("***", "*", "djid", 0, 5, currPageIndex, "**’” like '%" + str + "%'");
this.gw_select.DataSource = dt;
this.gw_select.DataKeyNames = new string[] { "***" };
this.gw_select.DataBind();
}
展开全部
把数据源给那个pager就ok 啊.
1-----------------------
DataSet ds = PycSQLHelper.SqlHelper.ExecuteDataset(PycSQLHelper.SqlHelper.StoreConnString, CommandType.Text, strSql1, parameter);
DataView dv = new DataView(ds.Tables[0]);
PagedDataSource pds = new PagedDataSource();
pds.AllowPaging = true;
pds.DataSource = dv;
AspNetPager1.RecordCount = dv.Count;
pds.CurrentPageIndex = page - 1;
AspNetPager1.CurrentPageIndex = page;
pds.PageSize = AspNetPager1.PageSize;
dl_qunall.DataSource = pds;
dl_qunall.DataBind();
------------------------
然后再在pager 的事件中绑定
protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
RepeaterDataBind(page);
}
1-----------------------
DataSet ds = PycSQLHelper.SqlHelper.ExecuteDataset(PycSQLHelper.SqlHelper.StoreConnString, CommandType.Text, strSql1, parameter);
DataView dv = new DataView(ds.Tables[0]);
PagedDataSource pds = new PagedDataSource();
pds.AllowPaging = true;
pds.DataSource = dv;
AspNetPager1.RecordCount = dv.Count;
pds.CurrentPageIndex = page - 1;
AspNetPager1.CurrentPageIndex = page;
pds.PageSize = AspNetPager1.PageSize;
dl_qunall.DataSource = pds;
dl_qunall.DataBind();
------------------------
然后再在pager 的事件中绑定
protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
RepeaterDataBind(page);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
没看懂你的意思,下面是DataList分页有关的代码,分页面和后台两部分代码.DataList有比GridView更好的用户自定义性,你可以将DateList自定义成一个表格或者DIV里面放一些label来绑定查询出的数据表中的数据.
页面代码:
<asp:LinkButton ID="lnkbtnFirst" runat="server" OnClick="lnkbtnFirst_Click">首页</asp:LinkButton>
<asp:LinkButton ID="lnkbtnFront" runat="server" OnClick="lnkbtnFront_Click">上一页</asp:LinkButton>
<asp:LinkButton ID="lnkbtnNext" runat="server" OnClick="lnkbtnNext_Click">下一页</asp:LinkButton>
<asp:LinkButton ID="lnkbtnLast" runat="server" OnClick="lnkbtnLast_Click">尾页</asp:LinkButton>
当前页码为:<asp:Label ID="labPage" runat="server" Text="1"></asp:Label>
总页码为:
<asp:Label ID="labBackPage" runat="server" Text="Label"></asp:Label>
后台代码:
PagedDataSource ps = new PagedDataSource();
protected void Bind()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConStrLeaveWord"].ConnectionString);
con.Open();
SqlDataAdapter sda = new SqlDataAdapter("select * from tbLeaveWord order by ID desc", con);
DataSet ds = new DataSet();
sda.Fill(ds, "tbLeaveWord");
//获取数据源
//调用分页方法
ps = GetPaging(ds, "tbLeaveWord", 5);
//设置当前页的索引
SettingPage(ps);
this.DataList1.DataSource = ps;
//this.DataList1.DataKeyField = "CustomerID";
DataList1.DataSource = ps;
DataList1.DataBind();
con.Close();
}
/// <summary>
/// 设置当前页的索引
/// </summary>
/// <param name="ps">分页的数据</param>
private void SettingPage(PagedDataSource ps)
{
//获取当前页
int curpage = Convert.ToInt32(this.labPage.Text);
ps.CurrentPageIndex = curpage - 1;
this.lnkbtnFront.Enabled = true;
this.lnkbtnNext.Enabled = true;
this.lnkbtnLast.Enabled = true;
this.lnkbtnFirst.Enabled = true;
if (curpage == 1)//等于第一页
{
this.lnkbtnFront.Enabled = false;
this.lnkbtnFirst.Enabled = false;
}
if (curpage == ps.PageCount)//等于最后一页
{
this.lnkbtnNext.Enabled = false;
this.lnkbtnLast.Enabled = false;
}
//显示总页数
this.labBackPage.Text = Convert.ToString(ps.PageCount);
}
/// <summary>
/// 获得数据源为DataSet对table分页 返回agedDataSource
/// </summary>
/// <param name="dataSet"> 数据源 DataSet</param>
/// <param name="tableName"> 表名</param>
/// <param name="pagSize"> 每页的页数</param>
/// <returns> </returns>
private PagedDataSource GetPaging(DataSet dataSet, string tableName, int pageSize)
{
PagedDataSource pageDataSource = new PagedDataSource();
pageDataSource.DataSource = dataSet.Tables[tableName].DefaultView;
pageDataSource.AllowPaging = true;
pageDataSource.PageSize = pageSize;
return pageDataSource;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind();
}
}
protected void lnkbtnFirst_Click(object sender, EventArgs e)
{
labPage.Text = "1";
Bind();
}
protected void lnkbtnLast_Click(object sender, EventArgs e)
{
labPage.Text = this.labBackPage.Text;
Bind();
}
protected void lnkbtnFront_Click(object sender, EventArgs e)
{
labPage.Text = (Convert.ToInt32(labPage.Text) - 1).ToString();
Bind();
}
protected void lnkbtnNext_Click(object sender, EventArgs e)
{
labPage.Text = (Convert.ToInt32(labPage.Text) + 1).ToString();
Bind();
}
页面代码:
<asp:LinkButton ID="lnkbtnFirst" runat="server" OnClick="lnkbtnFirst_Click">首页</asp:LinkButton>
<asp:LinkButton ID="lnkbtnFront" runat="server" OnClick="lnkbtnFront_Click">上一页</asp:LinkButton>
<asp:LinkButton ID="lnkbtnNext" runat="server" OnClick="lnkbtnNext_Click">下一页</asp:LinkButton>
<asp:LinkButton ID="lnkbtnLast" runat="server" OnClick="lnkbtnLast_Click">尾页</asp:LinkButton>
当前页码为:<asp:Label ID="labPage" runat="server" Text="1"></asp:Label>
总页码为:
<asp:Label ID="labBackPage" runat="server" Text="Label"></asp:Label>
后台代码:
PagedDataSource ps = new PagedDataSource();
protected void Bind()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConStrLeaveWord"].ConnectionString);
con.Open();
SqlDataAdapter sda = new SqlDataAdapter("select * from tbLeaveWord order by ID desc", con);
DataSet ds = new DataSet();
sda.Fill(ds, "tbLeaveWord");
//获取数据源
//调用分页方法
ps = GetPaging(ds, "tbLeaveWord", 5);
//设置当前页的索引
SettingPage(ps);
this.DataList1.DataSource = ps;
//this.DataList1.DataKeyField = "CustomerID";
DataList1.DataSource = ps;
DataList1.DataBind();
con.Close();
}
/// <summary>
/// 设置当前页的索引
/// </summary>
/// <param name="ps">分页的数据</param>
private void SettingPage(PagedDataSource ps)
{
//获取当前页
int curpage = Convert.ToInt32(this.labPage.Text);
ps.CurrentPageIndex = curpage - 1;
this.lnkbtnFront.Enabled = true;
this.lnkbtnNext.Enabled = true;
this.lnkbtnLast.Enabled = true;
this.lnkbtnFirst.Enabled = true;
if (curpage == 1)//等于第一页
{
this.lnkbtnFront.Enabled = false;
this.lnkbtnFirst.Enabled = false;
}
if (curpage == ps.PageCount)//等于最后一页
{
this.lnkbtnNext.Enabled = false;
this.lnkbtnLast.Enabled = false;
}
//显示总页数
this.labBackPage.Text = Convert.ToString(ps.PageCount);
}
/// <summary>
/// 获得数据源为DataSet对table分页 返回agedDataSource
/// </summary>
/// <param name="dataSet"> 数据源 DataSet</param>
/// <param name="tableName"> 表名</param>
/// <param name="pagSize"> 每页的页数</param>
/// <returns> </returns>
private PagedDataSource GetPaging(DataSet dataSet, string tableName, int pageSize)
{
PagedDataSource pageDataSource = new PagedDataSource();
pageDataSource.DataSource = dataSet.Tables[tableName].DefaultView;
pageDataSource.AllowPaging = true;
pageDataSource.PageSize = pageSize;
return pageDataSource;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind();
}
}
protected void lnkbtnFirst_Click(object sender, EventArgs e)
{
labPage.Text = "1";
Bind();
}
protected void lnkbtnLast_Click(object sender, EventArgs e)
{
labPage.Text = this.labBackPage.Text;
Bind();
}
protected void lnkbtnFront_Click(object sender, EventArgs e)
{
labPage.Text = (Convert.ToInt32(labPage.Text) - 1).ToString();
Bind();
}
protected void lnkbtnNext_Click(object sender, EventArgs e)
{
labPage.Text = (Convert.ToInt32(labPage.Text) + 1).ToString();
Bind();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询