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

enter image description here

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

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -