Unable to sort gridview bound to objectdatasource

Last post 12-06-2007 7:16 PM by workathome. 2 replies.

Sort Posts:

  • Unable to sort gridview bound to objectdatasource

    11-22-2007, 6:48 PM
    • Member
      29 point Member
    • workathome
    • Member since 04-25-2006, 11:40 AM
    • Posts 24

    I have been modifying the small business starter kit.  In the"News" portion of the website, I have a gridview with boundfields rather than a  template in the original code . I am reading all my data from the xml file.   I would like to be able to sort on my columns but I am getting the error message.

    The data source 'ObjectDataSourceAllProjects' does not support sorting with IEnumerable data. Automatic sorting is only supported with DataView, DataTable, and DataSet.

     

    Can I not do this?  I have searched this forum for similar posts and got a few matches but I don't understand what they are talking about.  Please help.  Below is my code.

           <div id="content-main-two-column">
                <h1>
                    Our Projects</h1>
                <hr />
                <!-- END MAIN COLUMN -->
                <asp:Panel ID="AllProjectsPanel" runat="server">
                    <%--Data Source Controls--%>
                    <asp:ObjectDataSource ID="ObjectDataSourceAllProjects" runat="server" SelectMethod="GetAllProjects"
                        TypeName="Projects" />
                    <asp:GridView ID="GridViewAllProjects" runat="server" AutoGenerateColumns="False" DataSourceID="ObjectDataSourceAllProjects"
                        AllowPaging="True" PageSize="15" OnRowCreated="GridViewAllProjects_RowCreated" BorderWidth="0"
                        BorderColor="white" CellPadding="6"  DataKeyNames="Id" AllowSorting="true" >
                        <HeaderStyle HorizontalAlign="Left" CssClass="ProjectHeader"  />
                        <RowStyle CssClass="ProjectData" />
                        <Columns>
                           <asp:BoundField DataField="title" HeaderText="Project Name" ItemStyle-Width="25%" SortExpression="title" />
                           <asp:BoundField DataField="year" HeaderText="Year" ItemStyle-Width="20%" SortExpression="year"/>
                           <asp:BoundField DataField="location" HeaderText="Location" ItemStyle-Width="20%" SortExpression="location" />
                           <asp:BoundField DataField="content" HeaderText="Project Type" ItemStyle-Width="35%" SortExpression="content" />
                        </Columns>
                        <PagerSettings Mode="NumericFirstLast" Position="TopAndBottom" />
                    </asp:GridView>
                </asp:Panel>
            </div>
     
  • Re: Unable to sort gridview bound to objectdatasource

    11-22-2007, 10:47 PM
    Answer
    • Contributor
      2,341 point Contributor
    • vijayvrr_2001
    • Member since 09-19-2007, 2:04 PM
    • Posts 394

    Hi

    Dataset and associated objects implement interfaces that allow the grid view to do sorting etc. I think you may want to either implement a custom comparer, or make use of the SortParameterName property of the ObjectDataSource control.

    See http://weblogs.asp.net/pjohnson/archive/2006/02/08/437731.aspx or http://www.codeproject.com/useritems/GridViewObjectDataSource.asp. Both of them give you complete code snippets on how to achieve this.

    HTH

    VJ

    If the reply answered your question please Mark it as "Answered". This would help people know that the question has been answered.
  • Re: Unable to sort gridview bound to objectdatasource

    12-06-2007, 7:16 PM
    • Member
      29 point Member
    • workathome
    • Member since 04-25-2006, 11:40 AM
    • Posts 24

    Thank you for your reply.  The articles and examples were helpful and I tried to implement the solution within my application but after a couple of hours I gave up and put all the data into a SQL database.  I understand the concepts but getting it to work within the context of the small business starter kit is beyond my limited programming capabilities.  Thanks again.

Page 1 of 1 (3 items)