Custome Paging using Stored Procedure

1 posts, 0 answers
  1. Kiresh
    Kiresh avatar
    24 posts
    Member since:
    Sep 2012

    Posted 05 Apr 2013 Link to this post

    I have problem with my development task.
    My ASPX File
    <telerik:RadGrid ID="grd1" runat="server" AllowFilteringByColumn="True"
                  AllowPaging="True" AllowCustomPaging="true" AutoGenerateColumns="False" GridLines="None"
                  OnItemDataBound="grd1_OnItemDataBound" OnItemCreated="grd1_ItemCreated"
                  Width="100%" Skin="Windows7" ShowGroupPanel="false" CellSpacing="0" PageSize="50"
                  OnNeedDataSource="grd1_NeedDataSource" OnPageIndexChanged="grd1_PageIndexChanged"

    and my Code file is
    protected void grd1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
            grd1.VirtualItemCount = 100000;
            grd1.DataSource = GetDataSource();
    private IEnumerable<SearchClass> Select(int pageSize, int pageIndex)
          IQueryable<SearchClass> searchObj = DataClassLib.Search(pageSize, pageIndex).AsQueryable();
            searchObj = searchObj .Select(x => new SearchClass
              Id = x.Id,
              Name = x.Name,
          catch (Exception ex)
            throw ex;
          return searchObj;
     private IEnumerable<SearchClass> GetDataSource()
          int pageIndex = grd1.CurrentPageIndex;
          int pageSize = grd1.PageSize;
          if (pageIndex == 0)
            pageIndex = 1;
          IEnumerable<SearchClass> data = Select(pageSize,pageIndex);
          return data == null ? new List<SearchClass>() : data.Skip(pageSize * pageIndex).Take(pageSize);

    i used Telerik RadGrid and i need to show pagination using Stored Procedure  where procedure returns only 50 records from database though there are 100K records in table.

    Paging showing correctly.
    using this code i get 50 records from database but does not appear in  grid , i debug my code and its shows me  in GetDataSource() that returns 50 records but when debug point comes to grd1.DataSource = GetDataSource(); this line in datasource it show me 0 count.

    can anybody guess why this happening

Back to Top