RadRadGrid custom paging(用户自定义分页)
感觉 RadGrid 用户自定义分页和asp.net pager很相似
需要注意的是1.启用AllowCustomPaging=true;
2.设置VirtualItemCount=表的总记录数
详细代码如下;
==============================================
aspx
----------------------------------------------------------------------
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<div class="div1">
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" AllowSorting="True" GridLines="None" AllowMultiRowSelection="True" OnNeedDataSource="RadGrid1_NeedDataSource" AllowCustomPaging="True">
<HeaderContextMenu EnableTheming="True">
<CollapseAnimation Duration="200" Type="OutQuint" />
</HeaderContextMenu>
<MasterTableView AutoGenerateColumns="False" ClientDataKeyNames="ZJID" CommandItemDisplay="Top" NoMasterRecordsText="没有记录显示">
<Columns>
<telerik:GridClientSelectColumn Reorderable="False" UniqueName="ClientSelectColumn" >
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" Width="40px" />
</telerik:GridClientSelectColumn>
<telerik:GridBoundColumn DataField="ID" DataType="System.Int32" HeaderText="序号"
ReadOnly="True" SortExpression="ID" UniqueName="ID">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="XM" HeaderText="姓名" SortExpression="XM"
UniqueName="XM">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
<SortingSettings SortedAscToolTip="正序" SortedDescToolTip="倒序" SortToolTip="单击排序" />
<ClientSettings EnableRowHoverStyle=True>
<Selecting AllowRowSelect="True" />
<ClientEvents OnRowDeselected="rowdeSelected" OnRowSelected="rowSelected" ></ClientEvents>
</ClientSettings>
<ExportSettings ExportOnlyData="True" IgnorePaging="True" OpenInNewWindow="True"></ExportSettings>
<FilterMenu EnableTheming="True">
<CollapseAnimation Duration="200" Type="OutQuint" />
</FilterMenu>
<PagerStyle Mode="Slider" />
</telerik:RadGrid>
</div>
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" AllowSorting="True" GridLines="None" AllowMultiRowSelection="True" OnNeedDataSource="RadGrid1_NeedDataSource" AllowCustomPaging="True">
<HeaderContextMenu EnableTheming="True">
<CollapseAnimation Duration="200" Type="OutQuint" />
</HeaderContextMenu>
<MasterTableView AutoGenerateColumns="False" ClientDataKeyNames="ZJID" CommandItemDisplay="Top" NoMasterRecordsText="没有记录显示">
<Columns>
<telerik:GridClientSelectColumn Reorderable="False" UniqueName="ClientSelectColumn" >
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" Width="40px" />
</telerik:GridClientSelectColumn>
<telerik:GridBoundColumn DataField="ID" DataType="System.Int32" HeaderText="序号"
ReadOnly="True" SortExpression="ID" UniqueName="ID">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="XM" HeaderText="姓名" SortExpression="XM"
UniqueName="XM">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
<SortingSettings SortedAscToolTip="正序" SortedDescToolTip="倒序" SortToolTip="单击排序" />
<ClientSettings EnableRowHoverStyle=True>
<Selecting AllowRowSelect="True" />
<ClientEvents OnRowDeselected="rowdeSelected" OnRowSelected="rowSelected" ></ClientEvents>
</ClientSettings>
<ExportSettings ExportOnlyData="True" IgnorePaging="True" OpenInNewWindow="True"></ExportSettings>
<FilterMenu EnableTheming="True">
<CollapseAnimation Duration="200" Type="OutQuint" />
</FilterMenu>
<PagerStyle Mode="Slider" />
</telerik:RadGrid>
</div>
------------------------------
cs代码
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
protected void Page_Load(object sender, EventArgs e)
{
SqlHelper helper = new SqlHelper();
string str = "select count(*) from Table1";
RadGrid1.VirtualItemCount = (int)helper.ExecuteScalar(str);
}
protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
int startRowIndex = RadGrid1.CurrentPageIndex * RadGrid1.PageSize;
SqlHelper helper = new SqlHelper();
//sql2005
string str = "select * from (select * , row_number() over( order by ID) as n from Table1) as t where n between " + startRowIndex + " and " + (startRowIndex + RadGrid1.PageSize) + "";
DataSet dt = helper.ExecuteDataSet(str);
RadGrid1.DataSource = dt;
}
{
SqlHelper helper = new SqlHelper();
string str = "select count(*) from Table1";
RadGrid1.VirtualItemCount = (int)helper.ExecuteScalar(str);
}
protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
int startRowIndex = RadGrid1.CurrentPageIndex * RadGrid1.PageSize;
SqlHelper helper = new SqlHelper();
//sql2005
string str = "select * from (select * , row_number() over( order by ID) as n from Table1) as t where n between " + startRowIndex + " and " + (startRowIndex + RadGrid1.PageSize) + "";
DataSet dt = helper.ExecuteDataSet(str);
RadGrid1.DataSource = dt;
}