向大虾们发问,关于AspNetPage分页控件
我看到一个关于AspNetPage分页控件,如下的写法:
DataSet ds;
SqlDataAdapter dr;
SqlCommand com;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection con = new SqlConnection("server=.;uid=sa;database=数据库");
con.Open();
com = new SqlCommand();
com.Connection = con;
com.CommandText = "select count(*) from Employees";
AspNetPager1.AlwaysShow=true;
AspNetPager1.PageSize=15;
AspNetPager1.RecordCount = (int)com.ExecuteScalar();
con.Close();
DataListDataBind();
}
}
private void DataListDataBind()
{
SqlConnection con = new SqlConnection("server=.;uid=sa;database=数据库");
dr = new SqlDataAdapter("select * from Employees", con);
ds = new DataSet();
dr.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "Employees");
DataList1.DataSource = ds.Tables["Employees"];
DataList1.DataBind();
}
protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
DataListDataBind();
}
我想问一下的是,如此写法,除了没有用存储过程不好外,还有什么不好之处。请教大虾啊
------解决方案--------------------如果用在项目中的话,这样不便于管理代码!
------解决方案--------------------跟我在大学的时候写的一样
没有任何结构可言!