Reputation: 14470
I have a list
where one item have 4 different elements
Item
Id int
Name String
Value String
Enable bool
I want to Bind the List<item>
to a gridview
. Currently I am displaying all the items. But I want to display only the Name
and Enable
fields only.
What is the easy way of doing this? Without creating new list
Thanks
Upvotes: 1
Views: 5261
Reputation: 223292
GridView.DataSource = from t in yourList
select new
{
t.Name,
t.Enable
};
Also check out the example to bind GridView using LINQ
Upvotes: 1
Reputation: 3183
Look at these LINQ articles to get you in the right direction - what you're actually looking for is LinQ projection http://msdn.microsoft.com/en-us/library/bb384087.aspx and use these Basic Query Operations for handling your select: http://msdn.microsoft.com/en-us/library/bb384087.aspx
Upvotes: 0
Reputation: 20640
The easiest way?
After binding, hide the columns you don't want to see.
GridView1.Columns[0].Visible = false;
Upvotes: 0