Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ASP.Net GridView

Posted on 2012-12-31
2
Medium Priority
?
346 Views
Last Modified: 2013-02-19
hello,

I have an iqueryable<objectextended> collection which is passed to a gridview.
I want to update the properties of objectextended before passing it onto the gridview.

I tried to convert IQueryable to List and update the items in the list and convert the list back to IQueryable, but it doe not work.

Thank You.
0
Comment
Question by:skolanti
2 Comments
 
LVL 18

Expert Comment

by:Gary Davis
ID: 38734623
Try to create a deep copy of the collection. That is, iterate through the items and create a new list and new items within the list. You can do this with a code loop or you can use Linq to project a new list of items using .Select().
0
 
LVL 8

Accepted Solution

by:
JustAndrei earned 1500 total points
ID: 38735229
I tried to convert IQueryable to List and update the items in the list and convert the list back to IQueryable, but it doe not work.
Surely you can't convert the list back to IQueryable, but you don't have to.
The GridView processes its data source with help of reflection: it just looks for certain properties of each data source item, no matter which type the latter is.
So, in general, the workflow is as follows:

1. Compose

Compose the query, which will give you an IQueryable.

2. Execute

Turn your query into a list. This is where your query will be executed in fact.

3. Project the results to a viewable form

Prepare the display data for your GridView in the linq Select method/expression. You may use a specific class or just an anonymous type.Of course, you may find it wise to combine or exchange steps 2 and 3.

4. Pass the data to the view

Pass the list to GridView.DataSource as an object. It will discover the items' properties you defined in your display [anonymous] type.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question