我用的数据库是ado+sql 2000,现在我从数据库中取出数据显示在dbgrid中之后,默认的是所有的数据都显示在一个页面中了,如果我有很多数据的话,查找起来很不方便的。
    能否让dbgrid分页显示数据哪?让我可以指定每次一个页面中显示几个,然后点击一个“上一页”,“下一页”等等的按钮来分开显示数据?

解决方案 »

  1.   

    可以用PageControl啊,在每个Page里放一个DBGrid。
      

  2.   

    回复人: loujing(楼竞 http://www.LouJing.Com) ( ) 信誉:100  2006-2-17 19:46:28  得分: 0  
     
     
       
    可以用PageControl啊,在每个Page里放一个DBGrid。  
     
    单独在dbgrid中不能实现吗?
      

  3.   

    好像不能,可以做成按钮(TButton)形式,点"下一页"或"上一页"就出来新的一页了.
    需要设置变量来记录:总页数,当前页数......
      

  4.   

    janezjtjdx() ( ) 信誉:100  2006-02-21 10:02:00  得分: 0  
     
     
       好像不能,可以做成按钮(TButton)形式,点"下一页"或"上一页"就出来新的一页了.
    需要设置变量来记录:总页数,当前页数......
      
     
    这样也可以啊,哈哈给个代码看看好吗?
      

  5.   

    我从我原来写的代码中摘出主要部分,供你参考。
    procedure TLogManage.DSELECT(num_per, cur_num, total: Integer); //num_per,每页记录条数,cut_num,当前页数
    begin
      if num_per * cur_num <= total then
      begin
        DM.dstlog.Active := False;
        DM.dstlog.CommandText := 'select * from LOGTABLE where lid in (select top ' + inttostr(num_per) + ' lid from  LOGTABLE  where lid in (select top ' +
          inttostr((cur_num) * num_per) + '  lid from LOGTABLE order by lid asc) order by lid  desc)order by lid asc';
        DM.dstlog.Active := True;
      end
      else begin
        DM.dstlog.Active := False;
        DM.dstlog.CommandText := 'select * from LOGTABLE where lid in (select top ' + inttostr(total - (cur_num - 1) * num_per) +
          '  lid from LOGTABLE order by lid desc) order by lid asc';
        DM.dstlog.Active := True;
      end;
    end;procedure TLogManage.MSELECT(num_per, cur_num, total: Integer; fieldname: string);
    begin
      if num_per * cur_num <= total then
      begin
        DM.dstlog.Active := False;
        DM.dstlog.CommandText := 'select * from LOGTABLE where lid in (select top ' + inttostr(num_per) + ' lid from  LOGTABLE  where lid in (select top ' + inttostr((cur_num) * num_per) +
          '  lid from LOGTABLE where lmodule=''' + fieldname + '''order by lid asc) and lmodule=''' + fieldname + '''order by lid  desc) order by lid asc';
        DM.dstlog.Active := True;
      end
      else begin
        DM.dstlog.Active := False;
        DM.dstlog.CommandText := 'select * from LOGTABLE where lid in (select top ' + inttostr(total - (cur_num - 1) * num_per) +
          '   lid from LOGTABLE  where lmodule=''' + fieldname + ''' order by lid desc) order by lid asc';
        DM.dstlog.Active := True;
      end;
    end;基本思路是用SQL语句控制的。