【问题标题】:Telerik RadGrid Bound to EntityFramework Paging does not functionTelerik RadGrid 绑定到 EntityFramework 分页不起作用
【发布时间】:2015-03-12 00:06:00
【问题描述】:

问题:“分页”在我的 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();
              }

【问题讨论】:

    标签: c# entity-framework telerik radgridview


    【解决方案1】:

    当您使用 .ToList() 时,您将在每次调用 LoadGrid() 时获取所有数据。

    另一种方法是使用&lt;asp:EntityDataSource /&gt; 并将其设置为RadGrid 的DataSourceID,它会自动从数据库中获取单页数据。

    然后您可以删除 LoadGrid() 函数。

    如果您发现 EntityDataSource 不足以满足您的需求,那么我建议使用高级 RadGrid 绑定,请参阅 http://www.telerik.com/help/aspnet-ajax/grid-advanced-data-binding.html

    【讨论】:

      猜你喜欢
      • 2015-02-11
      • 1970-01-01
      • 1970-01-01
      • 2014-12-27
      • 2011-04-02
      • 2012-09-22
      • 2010-10-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多