Reputation: 2305
First, start with two objects.
Object
{
int id {get; set;}
string description {get; set;}
}
ObjectName
{
int id {get;set;}
string name {get;set;}
}
Let's say I have your average gridview:
List<Object> = GetListOfObjects();
MyGridview.DataSource = List<Object>;
But I want one of the columns to come from the list of names, where the ids are the same.
Psuedocode:
the ID column from MyGridview = List<ObjectNames>.Where(x=> x.id = myGridview.Id);
So basically, replacing the column of IDs with the column of names with those ids. Is that possible to do? How would I approach this?
Upvotes: 0
Views: 74
Reputation: 7539
You need to make the data one datasource. You can create an anonymous type that will hold data from both collections.
var combined = from x in myobjects
join y in myobjectnames on x.id equals y.id
select new {
Id = x.Id,
Name = y.Name,
// any other data you need
}
Upvotes: 2