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

Sorting not working

5 Answers 108 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Iker Llanos
Top achievements
Rank 1
Iker Llanos asked on 07 Jan 2011, 09:07 AM
I'm trying to sort a ListView but no way. I will explain what I've done:

- I get a List of products that containt an Order field (Orden integer)
- I put this datasource to the listview and databind()
- In the ascx I have this code:
<asp:Panel ID="listViewPanelProductos" CssClass="ListViewList" runat="server">
    <telerik:RadListView ID="lvProductos" runat="server" AllowPaging="true" 
         EnableViewState="true" OnItemDataBound="lvProductos_ItemDataBound"
    ItemPlaceholderID="ProductosContainer" DataKeyNames="IdProducto">        
<SortExpressions>
            <telerik:RadListViewSortExpression FieldName="Orden" SortOrder="Ascending" />
        </SortExpressions>
        <LayoutTemplate>                        
            <fieldset id="fieldSet" class="fieldSet">                
                <asp:PlaceHolder ID="ProductosContainer" runat="server" />
                <div style="clear:both"></div>
                <table cellpadding="0" cellspacing="0" style="margin:auto; padding-top:15px;">
                    <tr>
                        <td>
                            <telerik:RadDataPager ID="pager" runat="server" PagedControlID="lvProductos" PageSize="10" Skin="Default" AllowSEOPaging="true" SEOPagingQueryPageKey="pag">
                                <Fields>
                                    <telerik:RadDataPagerButtonField FieldType="Prev" />
                                    <telerik:RadDataPagerButtonField FieldType="Numeric" />
                                    <telerik:RadDataPagerButtonField FieldType="Next" />
                                </Fields>
                            </telerik:RadDataPager>
                        </td>
                    </tr>
                </table>
            </fieldset>
        </LayoutTemplate>
        <ItemTemplate>        
            <div class="item">
                <div class="tituloProducto">
                    <h2>                        
                        <asp:HyperLink ID="lnkTitulo" Text='<%# Eval("Titulo") %>' ToolTip='<%# Eval("Titulo") %>'
                            runat="server" EnableViewState="false" />
                    </h2>
                </div>
                <div class="descripcionProducto">
                    <asp:Label ID="lblDescripcion" runat="server" EnableViewState="false"></asp:Label>
                </div>
            </div>
        </ItemTemplate>
.
.
.
.
.

- No sorting happens.

What am I doing wrong?

Thanks

5 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 07 Jan 2011, 06:15 PM
Hello Iker,

The correct approach when using simple data-binding is to call the DataBind() method on the first page load when !Page.IsPostBack and after handling some event (sort event for example). Keep in mind that if you choose simple data-binding, you will need to assign data-source and rebind the grid after each operation (paging, sorting, editing, etc.) - this copies exactly MS ListView behavior.

You can also review the corresponding online demo of the product which illustrates direct comparison between the simple and advanced binding of RadListView.

I hope this helps.

All the best,
Pavlina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Iker Llanos
Top achievements
Rank 1
answered on 10 Jan 2011, 12:30 PM
I'm trying this with an entity datasource and it doesn't work either:

<asp:Panel ID="listViewPanelProductos" CssClass="ListViewList" runat="server">
    <telerik:RadListView ID="lvProductos" runat="server" AllowPaging="true"
         EnableViewState="true" OnItemDataBound="lvProductos_ItemDataBound"
    ItemPlaceholderID="ProductosContainer" DataKeyNames="IdProducto" DataSourceID="dsProductos">       
        <LayoutTemplate>                       
            <fieldset id="fieldSet" class="fieldSet">               
                <asp:PlaceHolder ID="ProductosContainer" runat="server" />
                <div style="clear:both"></div>
                <table cellpadding="0" cellspacing="0" style="margin:auto; padding-top:15px;">
                    <tr>
                        <td>
                            <telerik:RadDataPager ID="pager" runat="server" PagedControlID="lvProductos" PageSize="10" Skin="Default" AllowSEOPaging="true" SEOPagingQueryPageKey="pag">
                                <Fields>
                                    <telerik:RadDataPagerButtonField FieldType="Prev" />
                                    <telerik:RadDataPagerButtonField FieldType="Numeric" />
                                    <telerik:RadDataPagerButtonField FieldType="Next" />
                                </Fields>
                            </telerik:RadDataPager>
                        </td>
                    </tr>
                </table>
            </fieldset>
        </LayoutTemplate>
        <ItemTemplate>       
            <div class="item">
                <div class="tituloProducto">
                    <h2>                       
                        <asp:HyperLink ID="lnkTitulo" Text='<%# Eval("Titulo") %>' ToolTip='<%# Eval("Titulo") %>'
                            runat="server" EnableViewState="false" />
                    </h2>
                </div>
                <div class="descripcionProducto">
                    <asp:Label ID="lblDescripcion" runat="server" EnableViewState="false"></asp:Label>
                </div>
            </div>
        </ItemTemplate>
 
<asp:EntityDataSource ID="dsProductos" runat="server"
    ConnectionString="name=Entities"
    DefaultContainerName="Entities" EntitySetName="productos"
    OrderBy="it.Orden ASC">
</asp:EntityDataSource>
0
Pavlina
Telerik team
answered on 11 Jan 2011, 12:57 PM
Hi Iker,

To enable sorting functionality for the RadListView  you should add a SortExpression object to the SortExpressions collection as demonstrated in the following help article:
http://www.telerik.com/help/aspnet-ajax/listview-sorting.html

Additionally, note that when Sort/Page commands are triggered RadListView requires to re-bind in order to process the command.
You can find list of commands the call rebind implicitly on the article bellow:
http://www.telerik.com/help/aspnet-ajax/listview-commands-invoking-rebind-implicitly.html

Greetings,
Pavlina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
JM
Top achievements
Rank 1
answered on 03 Mar 2011, 02:32 PM
It's probably a bug.. Try setting AllowPaging to  false.
0
Pavlina
Telerik team
answered on 08 Mar 2011, 03:47 PM
Hi,

To fix the problem with sorting, you will need to upgrade to the latest version of RadControls for ASP.NET AJAX:
http://www.telerik.com/support/kb/aspnet-ajax/general/updating-radcontrols-for-asp-net-to-another-version-or-license.aspx

Best wishes,
Pavlina
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
ListView
Asked by
Iker Llanos
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Iker Llanos
Top achievements
Rank 1
JM
Top achievements
Rank 1
Share this question
or