asp.net:使用aspnetpager分页控件,运行代码后只有1,2分页
数据一共有20条。。每页显示2条,那实际上就有10个分页,但aspnetpager分页控件只显示1和2分页,调试很多遍都没找出问题,求大神指教前台代码:这是分页控件<we...
数据一共有20条。。每页显示2条,那实际上就有10个分页,但aspnetpager分页控件只显示1和2分页,调试很多遍都没找出问题,求大神指教
前台代码:
这是分页控件
<webdiyer:AspNetPager ID="apUserPage" runat="server" HorizontalAlign="Center" Width="100%" PageIndexBoxType="DropDownList" ></webdiyer:AspNetPager>
数据显示用的是gridview,能正常显示
后台代码:
UsersManager um = new UsersManager();//用的三层结构,实例化
int currentPageNumber;//当前页号
int pageSize = 3;//每页显示记录条数
protected void Page_Load(object sender, EventArgs e)
{
currentPageNumber = 1;//当前页
ViewState["currentPageNumber"] = currentPageNumber;//保存当前页
getbind();
}
private void getbind()
{
currentPageNumber = Convert.ToInt32(ViewState["currentPageNumber"]);//读取当前页
this.apUserPage.RecordCount = um.GetUserCount();//得出总的记录条数
this.apUserPage.CurrentPageIndex = currentPageNumber;//控件赋值
this.gviUserList.DataSource = um.GetList(currentPageNumber,pageSize);//数据绑定
this.gviUserList.DataBind();
}
protected void apUserPage_PageChanged(object sender, EventArgs e)
{//控件事件
currentPageNumber = this.apUserPage.CurrentPageIndex;
ViewState["currentPageNumber"] = currentPageNumber;
getbind();
} 展开
前台代码:
这是分页控件
<webdiyer:AspNetPager ID="apUserPage" runat="server" HorizontalAlign="Center" Width="100%" PageIndexBoxType="DropDownList" ></webdiyer:AspNetPager>
数据显示用的是gridview,能正常显示
后台代码:
UsersManager um = new UsersManager();//用的三层结构,实例化
int currentPageNumber;//当前页号
int pageSize = 3;//每页显示记录条数
protected void Page_Load(object sender, EventArgs e)
{
currentPageNumber = 1;//当前页
ViewState["currentPageNumber"] = currentPageNumber;//保存当前页
getbind();
}
private void getbind()
{
currentPageNumber = Convert.ToInt32(ViewState["currentPageNumber"]);//读取当前页
this.apUserPage.RecordCount = um.GetUserCount();//得出总的记录条数
this.apUserPage.CurrentPageIndex = currentPageNumber;//控件赋值
this.gviUserList.DataSource = um.GetList(currentPageNumber,pageSize);//数据绑定
this.gviUserList.DataBind();
}
protected void apUserPage_PageChanged(object sender, EventArgs e)
{//控件事件
currentPageNumber = this.apUserPage.CurrentPageIndex;
ViewState["currentPageNumber"] = currentPageNumber;
getbind();
} 展开
4个回答
展开全部
你贴出来的代码,我是看的云里雾里的。
下面的代码你可以参考一下:
if(!IsPostBack)
{
bind();
page();
}
private void bind()
{
#region 绑定数据
SqlConnection strconn = Database.createConn();
strconn.Open();
if (tb_teachingName.Text.Trim() != "")
{
SqlDataAdapter dr = new SqlDataAdapter("select * from 表名 where u_user like'%" + tb_teachingName.Text.Trim() + "%'", strconn);
DataSet ds = new DataSet();
dr.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "表名");
strconn.Close();
rep_List.DataSource = ds.Tables["表名"];
rep_List.DataBind();
}
else
{
SqlDataAdapter dr = new SqlDataAdapter("select * from 表名", strconn);
DataSet ds = new DataSet();
dr.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "表名");
strconn.Close();
rep_List.DataSource = ds.Tables["表名"];
rep_List.DataBind();
}
#endregion
}
private void page()
{
#region 统计总记录
SqlConnection con = Database.createConn();
con.Open();
SqlCommand com = new SqlCommand();
if (tb_teachingName.Text.Trim() != "")
{
com.Connection = con;
com.CommandText = "select count(*) from 表名 where u_user like'%" + tb_teachingName.Text.Trim() + "%'";
AspNetPager1.AlwaysShow = true;
AspNetPager1.RecordCount = (int)com.ExecuteScalar();
con.Close();
}
else
{
com.Connection = con;
com.CommandText = "select count(*) from 表名";
AspNetPager1.AlwaysShow = true;
AspNetPager1.RecordCount = (int)com.ExecuteScalar();
con.Close();
}
#endregion
}
protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
bind();
}
下面的代码你可以参考一下:
if(!IsPostBack)
{
bind();
page();
}
private void bind()
{
#region 绑定数据
SqlConnection strconn = Database.createConn();
strconn.Open();
if (tb_teachingName.Text.Trim() != "")
{
SqlDataAdapter dr = new SqlDataAdapter("select * from 表名 where u_user like'%" + tb_teachingName.Text.Trim() + "%'", strconn);
DataSet ds = new DataSet();
dr.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "表名");
strconn.Close();
rep_List.DataSource = ds.Tables["表名"];
rep_List.DataBind();
}
else
{
SqlDataAdapter dr = new SqlDataAdapter("select * from 表名", strconn);
DataSet ds = new DataSet();
dr.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "表名");
strconn.Close();
rep_List.DataSource = ds.Tables["表名"];
rep_List.DataBind();
}
#endregion
}
private void page()
{
#region 统计总记录
SqlConnection con = Database.createConn();
con.Open();
SqlCommand com = new SqlCommand();
if (tb_teachingName.Text.Trim() != "")
{
com.Connection = con;
com.CommandText = "select count(*) from 表名 where u_user like'%" + tb_teachingName.Text.Trim() + "%'";
AspNetPager1.AlwaysShow = true;
AspNetPager1.RecordCount = (int)com.ExecuteScalar();
con.Close();
}
else
{
com.Connection = con;
com.CommandText = "select count(*) from 表名";
AspNetPager1.AlwaysShow = true;
AspNetPager1.RecordCount = (int)com.ExecuteScalar();
con.Close();
}
#endregion
}
protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
bind();
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<webdiyer:AspNetPager ID="apUserPage" runat="server" HorizontalAlign="Center" Width="100%" PageIndexBoxType="DropDownList" NumericButtonCount="5" ></webdiyer:AspNetPager>
在aspnetpager分页控制中加上 NumericButtonCount="5" 这个属性,表示显示1--5个分页页码。
在aspnetpager分页控制中加上 NumericButtonCount="5" 这个属性,表示显示1--5个分页页码。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我这里有个简单的例子,你可以看一下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-03-28
展开全部
inu是哪个国家代码
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询