我有GridView
,我想实现分页功能。这很好。
protected DataSet FillDataSet()
{
string source = "Database=GridTest;Server=Localhost;Trusted_Connection=yes";
con = new SqlConnection(source);
cmd = new SqlCommand("proc_mygrid", con);
ds = new DataSet();
da = new SqlDataAdapter(cmd);
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
return ds;
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
int newPagenumber = e.NewPageIndex;
GridView1.PageIndex = newPagenumber;
GridView1.DataSource = FillDataSet();
GridView1.DataBind();
}
但问题在于每个分页我都要调用FillDataSet();
。有没有办法阻止它。还有其他编码方法吗?
答案 0 :(得分:1)
看看Scott Mitchell的文章:Custom Paging in ASP.NET 2.0 with SQL Server 2005。
如果您使用的是2005之前版本的SQL Server,请尝试:A More Efficient Method for Paging Through Large Result Sets
答案 1 :(得分:0)