Webform里的Datagrid带自动分页的功能,只要设定Pagesize和Allowpage即可。可是,实现方法非常的弱智,每次都要把所有的数据都取来,然后再去计算总页数和当前页数。这样导致的问题是每次绑定/翻页都读一遍整个datasource,大数据量时简直是恶梦。

解决方法是用自定义分页Allowcustompage。以下是Sample Code,主要思路是在Store Procedue最后把结果输出到一个零时表,并加上Identity的字段用作分页用。实现起来比较容易,可以在Store Procedue中加上条件和排序变量。

Datagrid
Webform中DataGrid的自定义分页                    <asp:datagrid id="dgResult" runat="server" Font-Names="Verdana" Font-Size="10pt" Width="100%" AllowPaging="True" PageSize="10"    AutoGenerateColumns="False"  AllowCustomPaging="True">
Webform中DataGrid的自定义分页                        
<Columns>
Webform中DataGrid的自定义分页                            
<asp:BoundColumn DataField="Name" HeaderText="Name">
Webform中DataGrid的自定义分页                                
<HeaderStyle Width="100px">HeaderStyle>
Webform中DataGrid的自定义分页                            
asp:BoundColumn>
Webform中DataGrid的自定义分页                            
<asp:BoundColumn DataField="Gender" HeaderText="Gender">
Webform中DataGrid的自定义分页                                
<HeaderStyle Width="70px">HeaderStyle>
Webform中DataGrid的自定义分页                            
asp:BoundColumn>
Webform中DataGrid的自定义分页                        
Columns>
Webform中DataGrid的自定义分页                        
<PagerStyle  Mode="NumericPages"      PageButtonCount="10">PagerStyle>
Webform中DataGrid的自定义分页                    
asp:datagrid>


BindData

End Sub

getResultNumber
End Function

getResult
End Function

spGetResultNumber
Webform中DataGrid的自定义分页CREATE PROCEDURE [dbo].[spGetResultNumber] 
Webform中DataGrid的自定义分页
Webform中DataGrid的自定义分页
AS 
Webform中DataGrid的自定义分页
Webform中DataGrid的自定义分页
Begin
Webform中DataGrid的自定义分页
Webform中DataGrid的自定义分页
Select  RecordID, Name,Gender into #tempResult from tblSample
Webform中DataGrid的自定义分页
Webform中DataGrid的自定义分页
Select @recordsNum=count(RecordID) From #tempResult
Webform中DataGrid的自定义分页
Webform中DataGrid的自定义分页
end
Webform中DataGrid的自定义分页
GO

spGetResult

Webform中DataGrid的自定义分页CREATE PROCEDURE [dbo].[spGetResult] 
Webform中DataGrid的自定义分页
Webform中DataGrid的自定义分页@startIndex 
int,
Webform中DataGrid的自定义分页@endIndex 
int
Webform中DataGrid的自定义分页
Webform中DataGrid的自定义分页
AS 
Webform中DataGrid的自定义分页
Webform中DataGrid的自定义分页
Begin
Webform中DataGrid的自定义分页
Webform中DataGrid的自定义分页
--New a field PKID for paging
Webform中DataGrid的自定义分页
Select  identity(int,1,1as PKID, RecordID, Name,Gender into #tempResult from tblSample
Webform中DataGrid的自定义分页
Webform中DataGrid的自定义分页
Select * from #tempResult where PKID between @startIndex and @endIndex 
Webform中DataGrid的自定义分页
Webform中DataGrid的自定义分页
end
Webform中DataGrid的自定义分页
GO

相关文章:

  • 2022-01-08
  • 2021-11-12
  • 2022-12-23
  • 2021-07-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-04
  • 2021-10-04
  • 2021-06-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-20
相关资源
相似解决方案