tags:

views:

460

answers:

1

If you followed my previous post

var filteredUser = from U in collection
                               select new  {U.fname,U.lname};
            gridView.DataSource = filteredUser;
            gridView.DataBind();

Now I am trying to do this:

  1. Format the column names based on properties of U. So for example if U.fname chancges to U.FirstName then I want my gridview column name to reflect the same

  2. If I enable paging through the design view, code compiles but when I launch the web app, it fails stating 'The data source does not support server-side data paging'

Edit::Found this for item # 2 link text

+1  A: 

1) Are you using AutoGenerateColumns="True" on your GridView or binding them yourself? I would think that (1) would work if AutoGenerateColumns is true. You lose a lot of control over how the columns are displayed, but it ought to work. If you are binding them yourself, I think you will just need to update the bound column names whenever the name of the data field changes or alias the name in the select clause so that it remains the same.

var filteredUser = from U in collection
                   select new  {FirstName = U.fname, LastName = U.lname};

2) Does your collection support IEnumerable<U> or just IEnumerable? I believe that LINQ uses Skip() and Take() to support paging so it would need to support the generic enumerable interface.

tvanfosson
my collection derives from Collection<> which if memory serves me correct implements IEnumerable<>.If Linq supports paging then would i still need to set<asp:GridView ID="gridView" Width="100%" runat="server" AllowSorting="True" AutoGenerateColumns="true" PageSize="5" AllowPaging="true">
I think maybe the problem is that you are binding it dynamically rather than declaratively. Thus the data source has no way to communicate back the paging parameters. Can you change it so that you bind the datasource declaratively? You can always replace the result by overriding OnSelecting.
tvanfosson
tvanfosson: what do you mean bind it declaratively? create an objectdatasource and bind that to my collection? I have a dataaccess layer which gets the reccords from the db using enterprise library and i want to use my data access layer to build my gridview