Linq to EF4 sorting/paging in RadGrid_NeedDataSource handler

Thread is closed for posting
2 posts, 0 answers
  1. Brooks
    Brooks avatar
    4 posts
    Member since:
    Jan 2012

    Posted 21 Mar 2012 Link to this post

    I handle my sorting and paging explicitly in my entity framework calls from a NeedDataSource handler.

    I persist the settings in session, and when I return to a page with a radgrid, I get the previous sort order and page correctly displayed...but I don't see how to highlight the sort column and its header to indicate the sort and sort direction.

    I expected I could do so in the ItemDataBound handlers, but it eludes me! (I attempted to use a SortExpression, hoping it would at least trip the column indications even though there is no sorting to be done by luck there either)

    Can anyone help?


    Oops! Not MVC...but RadGrid for AJAX
  2. Brooks
    Brooks avatar
    4 posts
    Member since:
    Jan 2012

    Posted 22 Mar 2012 Link to this post

    I figured it out!

    The GridSortExpression.FieldName property is a needs to match the SortExpression of the column in question...not the column DataField and not the column UniqueName.

    For instance, to sort on this column:

    <telerik:GridBoundColumn UniqueName="UserLastName" SortExpression="LastName,FirstName"
        HeaderAbbr="Last" HeaderText="Last Name" HeaderButtonType="TextButton"  DataField="LastName" />

    My NeedDataSource handler does this:

    if (_showPersistedPage)
    GridSettings gs = Session.UserListSettings;
    trg_UserList.DataSource = UberUserView.GetOrderedEntityUserList(_entityId, gs.SortExpression.Split(
    ','), gs.SortOrder, (int)gs.StartRowIndex, (int)gs.PageSize, true);
    trg_UserList.CurrentPageIndex = (
    trg_UserList.PageSize = (

    GridSortExpression exp =
    new GridSortExpression();
    exp.FieldName = gs.OrderBy;  //OrderBy is "LastName,FirstName"  It was failing when "LastName" or "UserLastName" was used.

    To Telerik: this did not standout in the documentation!
Back to Top