AspNetPager控件对Datalist进行分页
卫生么分页出来了,却不显示数据库内容(代码如下)usingSystem;usingSystem.Data;usingSystem.Configuration;usingS...
卫生么分页出来了,却不显示数据库内容(代码如下)
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.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
DataSet ds;
SqlDataAdapter dr;
SqlCommand com;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection con = new SqlConnection("server=localhost;database=zuopin;trusted_connection=sspi");
con.Open();
com = new SqlCommand();
com.Connection = con;
com.CommandText = "select count(*) from asd";
AspNetPager1.AlwaysShow = true;
AspNetPager1.PageSize = 6;
AspNetPager1.RecordCount = (int)com.ExecuteScalar();
DataList1.DataBind();
con.Close();
DataListDataBind();
}
}
private void DataListDataBind()
{
SqlConnection con = new SqlConnection("server=localhost;database=zuopin;trusted_connection=sspi");
dr = new SqlDataAdapter("select * from asd", con);
ds = new DataSet();
dr.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "asd");
DataList1.DataSource = ds.Tables["asd"];
DataList1.DataBind();
}
protected void AspNetPager1_PageChanged(object src, EventArgs e)
{
DataListDataBind();
}
} 展开
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.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
DataSet ds;
SqlDataAdapter dr;
SqlCommand com;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection con = new SqlConnection("server=localhost;database=zuopin;trusted_connection=sspi");
con.Open();
com = new SqlCommand();
com.Connection = con;
com.CommandText = "select count(*) from asd";
AspNetPager1.AlwaysShow = true;
AspNetPager1.PageSize = 6;
AspNetPager1.RecordCount = (int)com.ExecuteScalar();
DataList1.DataBind();
con.Close();
DataListDataBind();
}
}
private void DataListDataBind()
{
SqlConnection con = new SqlConnection("server=localhost;database=zuopin;trusted_connection=sspi");
dr = new SqlDataAdapter("select * from asd", con);
ds = new DataSet();
dr.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "asd");
DataList1.DataSource = ds.Tables["asd"];
DataList1.DataBind();
}
protected void AspNetPager1_PageChanged(object src, EventArgs e)
{
DataListDataBind();
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询