您的位置:首页 > 编程语言 > ASP

asp.net分页控件实例源码

2013-04-25 08:59 543 查看
DataSet ds;

SqlDataAdapter dr;

SqlCommand com;

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

AspNetPager1.AlwaysShow = true;

AspNetPager1.PageSize = 1;

AspNetPager1.RecordCount = Convert.ToInt32(DBClass.ExecuteScalar("select count(*) from StudentsWenDaTi where StudentsID = @StudentsID", new SqlParameter("StudentsID", Request.QueryString["id"]))); //数据库中有多少条记录

RepeaterDataBind();

}

}

private void RepeaterDataBind()

{

string strsql = string.Format("select * from StudentsWenDaTi where StudentsID='{0}'", Request.QueryString["id"]);

string strconn = System.Configuration.ConfigurationManager.ConnectionStrings["StrCon"].ToString();

SqlConnection con = new SqlConnection(strconn);

con.Open();

dr = new SqlDataAdapter(strsql ,con);

ds = new DataSet();

dr.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "Article");

this.DataList1.DataSource = ds.Tables["Article"];

this.DataList1.DataBind();

}

protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)

{

//分页

AspNetPager1.CurrentPageIndex = e.NewPageIndex;

RepeaterDataBind();

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: