This is a migrated thread and some comments may be shown as answers.

RadGrid no Paging Client Side ASP.NET

2 Answers 124 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eduardo
Top achievements
Rank 1
Eduardo asked on 01 Apr 2014, 08:48 PM

Hi everyone

Im trying to load data in RadGrid, everything is right except no paging, 

I click on page number to change the page but no paging occurs or no data is rendered

I use GetDataAndCount event to load the data, the output type of the method is ResultData (this class contains a generic list and counter) 

I think Im missing something, can you help me.

I provide some code:


<telerik:RadGrid ID="GvProfiles" runat="server" AllowPaging="true" AllowCustomPaging="false"
                AllowSorting="true" AllowFilteringByColumn="true" FilterType="CheckList" ShowFooter="true">
                <MasterTableView AutoGenerateColumns="false" DataKeyNames="ProfileID" ClientDataKeyNames="ProfileID" CheckListWebServicePath="ProfilesService.svc">
                    <PagerStyle Mode="NumericPages"></PagerStyle>
                    <Columns>
                        <telerik:GridBoundColumn FilterDelay="200" FilterCheckListWebServiceMethod="GetProfileNames"
                            DataField="ProfileName" HeaderText="Profile Name" UniqueName="ProfileID" DataType="System.String">
                        </telerik:GridBoundColumn>
                    </Columns>
                    <PagerStyle AlwaysVisible="true"></PagerStyle>
                </MasterTableView>
                <ClientSettings>
                    <ClientEvents OnDataBound="OnDataBound" OnGridCreated="OnGridCreated" />
                    <DataBinding SelectMethod="GetDataAndCount"     Location="ProfilesService.svc"
                    SortParameterType="String" FilterParameterType="String">
                    </DataBinding>
                </ClientSettings>
                <FilterMenu CssClass="RadFilterMenu_CheckList">
                </FilterMenu>
            </telerik:RadGrid>




[DataContract]
public class Profiles
{
    [DataMember]
    public Int64 ProfileID { get; set; }

    [DataMember]
    public String ProfileName { get; set; }
}

public class ResultData
{
    public int Count { get; set; }
    public List<Profiles> Data { get; set; }
}

[ServiceKnownType(typeof(Profiles))]
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class ProfilesService
{
    [OperationContract]
    public RadListBoxItemData[] GetProfileNames(Dictionary<string, object> context)
    {
        BusinessLayer.ProfilesBL objProfilesBL = new BusinessLayer.ProfilesBL();
        List<DataLayer.Profiles> listProfiles = new List<DataLayer.Profiles>();
        List<Profiles> listWcfProfiles = new List<Profiles>();

        try
        {
            listProfiles = objProfilesBL.Select(new DataLayer.Profiles());

            listProfiles.ForEach(delegate(DataLayer.Profiles item)
            {
                listWcfProfiles.Add(new Profiles { ProfileID = item.ProfileID, ProfileName = item.ProfileName });
            });

            return listWcfProfiles.Select(o => new RadListBoxItemData { Text = o.ProfileName, Value = o.ProfileID.ToString() }).ToArray<RadListBoxItemData>();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            objProfilesBL = null;
            listProfiles = null;
            listWcfProfiles = null;
        }
    }

    [OperationContract]
    public ResultData GetDataAndCount(int startRowIndex, int maximumRows, string sortExpression, string filterExpression)
    {
        BusinessLayer.ProfilesBL objProfilesBL = new BusinessLayer.ProfilesBL();
        List<DataLayer.Profiles> listProfiles = new List<DataLayer.Profiles>();

        IQueryable iQueryable;
        GridLinqBindingData gridLinqBindingData;
        ResultData resultData = new ResultData();
        List<Profiles> listProfilesService = new List<Profiles>();

        try
        {
            listProfiles = objProfilesBL.Select(new DataLayer.Profiles());

            iQueryable = listProfiles.AsQueryable();

            gridLinqBindingData = RadGrid.GetBindingData(iQueryable, startRowIndex, maximumRows, string.Empty, string.Empty);

            if (string.IsNullOrEmpty(sortExpression))
                sortExpression = "ProfileName ASC";

            if (!string.IsNullOrEmpty(filterExpression))
            {
                filterExpression = filterExpression.Replace("[", string.Empty);
                filterExpression = filterExpression.Replace("]", string.Empty);
                filterExpression = filterExpression.Replace("'", "\"");
            }
            else
                filterExpression = "ProfileID > 0";

            resultData.Data = gridLinqBindingData.Data.OfType<DataLayer.Profiles>().Select(o => new Profiles()
            {
                ProfileID = o.ProfileID,
                ProfileName = o.ProfileName
            }).Where(filterExpression).OrderBy(sortExpression).ToList();

            resultData.Count = listProfiles.Count;

            return resultData;
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            objProfilesBL = null;
            listProfiles = null;
            iQueryable = null;
            gridLinqBindingData = null;
            resultData = null;
        }
    }

2 Answers, 1 is accepted

Sort by
0
Eduardo
Top achievements
Rank 1
answered on 01 Apr 2014, 09:25 PM
I checked the code and I realized the paging doesnt work when for example my PageSize is 5 and the generic list data has less than 5 items.

Can you help me. Please
0
Antonio Stoilkov
Telerik team
answered on 04 Apr 2014, 08:06 AM
Hi Eduardo,

Based on your description it is hard to determine the cause of the problem. In your last you have said that the problem replicates when the total number of items is lower than the PageSize value. However, if the total number of items is less than the PageSize there should be no paging at all and no other pages because there are no more records.

In order to further investigate the problem we will need more detailed information in what scenarios your application have incorrect behavior and provide a sample project showing the unwanted behavior so we could debug it and advice you with the best possible solution.

Regards,
Antonio Stoilkov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Eduardo
Top achievements
Rank 1
Answers by
Eduardo
Top achievements
Rank 1
Antonio Stoilkov
Telerik team
Share this question
or