问题:“分页”不适用于我的Telerik RadView,也不适用于“页面大小”。 黑色的作品,但用红色圈出的不是:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="TGrid">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="TGrid"> </telerik:AjaxUpdatedControl>
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadGrid ID="TGrid" runat="server" Skin="MetroTouch" ClientSettings-Virtualization-LoadingPanelID="RALoading" CssClass="RadGrid_Rounded" AllowPaging="True" PageSize="5" AllowSorting="True" OnPageIndexChanged="TGrid_PageIndexChanged" OnPageSizeChanged="TGrid_PageSizeChanged" AutoGenerateColumns="false" OnDataBound="TGrid_DataBound" >
<PagerStyle Mode="NextPrevNumericAndAdvanced" ></PagerStyle>
<MasterTableView Width="100%" DataKeyNames="SubmissionID">
<Columns>
//columns here
</Columns>
</MasterTableView>
</telerik:RadGrid>
这是它所绑定的数据源:
protected void LoadGrid()
{
TGrid.DataSource = dbContext.Mains.OrderByDescending(x => x.VoteCount).ToList();
TGrid.DataBind();
}
分页功能:
protected void TGrid_PageIndexChanged(object sender, GridPageChangedEventArgs e)
{
if (e != null)
{
TGrid.CurrentPageIndex = e.NewPageIndex;
TGrid.TabIndex = e.Item.TabIndex;
TGrid.DataSource = ViewState["Grid"];
TGrid.DataBind();
}
}
页面大小更改功能:
protected void TGrid_PageSizeChanged(object sender, GridPageSizeChangedEventArgs e)
{
TGrid.PageSize = e.NewPageSize;
TGrid.DataSource = ViewState["Grid"];
TGrid.DataBind();
}
答案 0 :(得分:0)
当您使用.ToList()
时,您将在每次调用LoadGrid()时获取所有数据。
将自动从数据库中获取单页数据的替代方法是使用<asp:EntityDataSource />
并将其设置为RadGrid的DataSourceID
。
然后,您可以删除LoadGrid()函数。
如果您发现EntityDataSource不足以满足您的需求,那么我建议使用高级RadGrid绑定,请参阅http://www.telerik.com/help/aspnet-ajax/grid-advanced-data-binding.html