adamcodes
adamcodes

Reputation: 1606

How to persist the DropDownList DataSource, populated from Linq query

I am populating a DropDownList from some Linq query, such as

var myTypes = from tableAlias in MyContext.MyTable ...;
dddTypes.DataSource = myTypes;

I want to be able to save the Linq query result either from myTypes or the DropDownList DataSource, so that it could be used in other methods. A variable of type var can only be local.

What does the data need to be casted to? Thanks.

Upvotes: 0

Views: 345

Answers (2)

Jen Grant
Jen Grant

Reputation: 2074

IEnumerable<MyTable> or you could just convert it to a list with myTypes.ToList(). The var variable actually is typed by the ling query, so if you add a break point after the query and hover over the myTypes variable, Intellisense will show you the type.

Upvotes: 2

JonH
JonH

Reputation: 33163

What if myTypes was stored as a dataset? You could then maintain the data via the dataset. A datasource can be assigned from the value of a dataset.

And now that you also mentioned you're using asp.net that dataset can be stored in a session state if required.

See this

Upvotes: 0

Related Questions