ExtJs的.NET控件----YuiGrid(分页/在线编辑)2010-07-17 博客园 Beniao一、分页YuiGrid的分页机制不是很强大,内置有两种分页样式,下图便是其中的一种.

本示例代码是借鉴于YuiGrid源代码中的测试案例的代码,使用MSSQL2005数据库,下面为分页查询的代码:
1public static DataTable GetPagedMovies(string sort,int offset,int page_size,string dir )
2{
3 SqlConnection con = new SqlConnection();
4 con.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
5 con.Open();
6
7
8 offset = offset / page_size;
9
10 offset += 1;
11 //query that gets only the records needed to the page
12 //using the new ROW_NUMBER function in sql2005
13 string sql = "WITH MOVIES AS ( " +
14 " SELECT ROW_NUMBER() OVER " +
15 "(ORDER BY " + sort + " " + dir + ")AS Row," +
16 " ID_MOVIE,TITLE, RATING,VOTES,YEAR,GENRE " +
17 " FROM TB_MOVIE )" +
18 " SELECT ID_MOVIE,TITLE, GENRE,RATING,VOTES,YEAR" +
19 " FROM MOVIES " +
20 " WHERE Row between (@PageIndex-1)* @PageSize+1 and @PageIndex*@PageSize";
21
22 SqlCommand cmd = new SqlCommand(sql, con);
23 //add the parameters to the query to grab the correct page
24 cmd.Parameters.AddWithValue("@PageIndex", offset);
25 cmd.Parameters.AddWithValue("@PageSize", page_size);
26 SqlDataAdapter adapt = new SqlDataAdapter(cmd);
27 DataSet ds = new DataSet();
28 adapt.Fill(ds);
29 //closes the objects and disposes
30
31 //GetMovieCount(ds);
32 con.Close();
33 cmd.Dispose();
34 con.Dispose();
35 return ds.Tables[0];
36}