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

Sorting while bound to EntityDataSource

3 Answers 121 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Glenn
Top achievements
Rank 1
Glenn asked on 09 Mar 2012, 02:11 PM
Hello,

While working on a Grid we integrated in one of our pages, I noticed how the sorting was not working properly. When trying to sort, the column gets marked as sorted (either asc or desc), but the actual items in the grid do not get sorted at all, they stay in the exact same order as they were before.

Trying to figure out what the problem was, I seem to have gotten the problem down to its core: the EntityDataSource bound via the RadGrid_NeedDataSource event handler.

Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" MasterPageFile="~/Site.master" Theme="EventDrive" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
 
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
 
<telerik:RadScriptManager ID="RadScriptManager" runat="server" />
 
<telerik:RadGrid ID="RadGrid1" OnNeedDataSource="RadGrid_NeedDataSource"
        runat="server" AllowPaging="True" AllowSorting="True">
</telerik:RadGrid>
 
<asp:EntityDataSource ID="edsED" runat="server" ConnectionString="name=EventdriveEntities"
DefaultContainerName="EventdriveEntities" EntitySetName="Person" AutoSort="true" />
 
</asp:Content>

Code Behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
 
public partial class test : System.Web.UI.Page
{
    protected void RadGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        edsED.Where = "it.EventID = 2324"; //fetch EventID here.
        RadGrid1.DataSource = edsED;
    }
}

Is this a known issue? Is there anything I can do to resolve this problem?

Any help would be more than welcome!


Thanks,

Glenn

3 Answers, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 1
answered on 13 Mar 2012, 02:48 PM
Glenn:

RadGrid used with an EntityDataSource supports sorting out-of-the-box. So, when RadGrid is bound to an EntityDataSource and Sort is executed, the sorting is done by the EntityDataSource control directly but through the grid mechanisms.

Not sure if you've already seen this older thread which contains insights from Telerik Admin and also a working demo project that could help determine what's going wrong:

Custom Paging and Sorting in Entity Framework 4

Hope this helps!
0
Glenn
Top achievements
Rank 1
answered on 16 Mar 2012, 09:57 AM
Hello jumpstart,

Yes, I know it's supported out of the box, and I've gotten it work before, when I've bound the EntityDatasource to the Grid directly through the DatasourceID parameter. The problem, though, seems to be that the sorting isn't done when I bind the Datasource via the OnNeedDatasource event handler: Even though the Grid will indicate that the content is sorted, no actual sorting seems to happen.

Thanks for your help so far, though :)
0
Richard
Top achievements
Rank 1
answered on 16 Mar 2012, 05:18 PM
Glenn:

Have you tried setting the EnableViewState="false" to see if the sorting refreshes the display of data? See the description area of the Grid/Advanced Data Binding online demo for insights on this setting and forcing a rebind of data on sorting.

Not sure if you'd have to handle the sorting manually, otherwise, if your binding with advanced data binding.

Regards,
Tags
Grid
Asked by
Glenn
Top achievements
Rank 1
Answers by
Richard
Top achievements
Rank 1
Glenn
Top achievements
Rank 1
Share this question
or