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

Sorting a RadGrid with IEnumerable<T> and yield keyword

1 Answer 82 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 04 May 2012, 09:11 PM
Why doesn't sorting work when you bind an IEnumerable<T> collection that uses the yield keyword?  Do I have to implement a custom paging solution?  I am using 2012 Q1 SP1 controls.

<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource">
    <MasterTableView AllowSorting="true" AllowPaging="true" PageSize="20" AllowFilteringByColumn="true" />
</telerik:RadGrid>

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.Linq;
using System.Linq;
 
using Telerik.Web.UI;
 
public class Class1
{
    public Class1(int i)
    {
        this.Column1 = i.ToString();
        this.Column2 = (200 - i).ToString();
        this.Column3 = System.Text.Encoding.Default.GetString(new[] { System.Convert.ToByte(65 + (i % 26)) });
    }
 
    public string Column1 { get; set; }
    public string Column2 { get; set; }
    public string Column3 { get; set; }
 
    public static IEnumerable<Class1> GetData()
    {
        List<Class1> data = new List<Class1>();
 
        for (int i = 0; i < 200; i++)
        {
            yield return new Class1(i);
        }
    }
}
 
public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
 
    protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        //RadGrid1.DataSource = Class1.GetData().ToArray();  //works
        RadGrid1.DataSource = Class1.GetData();  //doesn't work
    }
}

1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 09 May 2012, 11:41 AM
Hi Jason,

This problem has already been addressed in the latest internal build of RadControls. You can download it from your Telerik account and see if the grid now behaves as expected.

Greetings,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Jason
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or