asp.net - Bind data to grid view using LINQ with out adding DataClasses -
i have seen many articles using linq
bind gridview
, in using dataclasses
. possible bind data grid view using linq
out adding dataclasses
.. can 1 give me sample code or working example on this
i think may missing point, whatever source of data, long it's form of collection, can use linq objects query data. example:
public partial class webusercontrol1 : system.web.ui.usercontrol { private readonly list<dataitem> _items; public webusercontrol1() { _items = new list<dataitem> { new dataitem {name = "fred"}, new dataitem {name = "dave"}, new dataitem {name = "john"}, }; } protected void page_load(object sender, eventargs e) { // data , use linq objects var filtereddata = getdata().where(i => i.name.startswith("f")).tolist(); // bind data gridview1.datasource = filtereddata; gridview1.databind(); } private ienumerable<dataitem> getdata() { // data data source return _items; } } public class dataitem { public string name { get; set; } }
if data database, option use linq sql (sql server only) or linq entities (not sql server), or linq datasets (if have to).
Comments
Post a Comment