spnetPager的使用,新生相互交流,老手来给点意见(二)
接着上面的,Aspnetpager首先要知道两个值:
RecordCount 和PageSize,RecordCount是查询的记录总数, PageSize是每页显示的记录数.
下面介绍个直接写的列子,希望给新手有点帮助.
using Wuqi.Webdiyer;
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
this.recordBind(); }
}
public void bind()
{
SqlConnection sqlconn = new SqlConnection(mysql);
string cmd = "select * from city";
sqlconn.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd,sqlconn);
DataSet ds = new DataSet();
da.Fill(ds,this.AspNetPager3.PageSize*(this.AspNetPager3.CurrentPageIndex-1),this.AspNetPager3.PageSize,"city"); //注意这个地方
this.GridView1.DataSource = ds.Tables["city"];
this.GridView1.DataBind();
}
public void recordBind()
{
SqlConnection sqlconn = new SqlConnection(mysql);
string cmd = "select count(*) from city";
sqlconn.Open();
SqlCommand sqlcommd = new SqlCommand(cmd,sqlconn);
this.AspNetPager3.RecordCount = (int)sqlcommd.ExecuteScalar(); //查询总的记录数
sqlconn.Close();
this.bind();
}
protected void AspNetPager3_PageChanged(object sender, EventArgs e) //必须的
{
this.bind();
}
}
红字的地方都是要注意的. 这次就到这,希望对你有帮助!
浙公网安备 33010602011771号