feipeng

不要过分强调技术,思想才是关键!
  新随笔  :: 管理

优化GridView的查询、翻页性能

Posted on 2007-07-30 16:45  FrankFei  阅读(1950)  评论(2编辑  收藏  举报

最近在工作中使用到了GridView这个控件,很好用,可当绑定数据量较大时,就会有性能问题,经过分析,找到了一种可以解决这个问题的方法,其实质是下面的SQL(Oracle)语句:

select a.*
  from (select rownum as row_id, b.*
          from (select * from table_name order by column_name asc) b) a
 where a.row_id between record_begin_index and record_end_index

其中table_name表示需要查询的表名,column_name是要排序的列名,record_begin_index是要显示的表中第record_begin_index行的开始位置,record_end_index是要显示的表中第record_end_index行的结束位置,如果我想查询表中第101行到120行的数据,上面where后的语句就是:a.row_id between 101 and 120。

当然上面的SQL语句最好能写成Procedure,再结合.NET Framework 2.0中的ObjectDataSource就可以了(关于ObjectDataSource的使用,网上有很多例子,这里就不赘述了)。