asp.net - How can bind list to GridView -


i have list in class , want use of list in other class , bind gridview.

in class make list :

namespace sample_table { public class classdal {     public list<phone> getall()     {         using (practicedbentities1 context = new practicedbentities1())         {             return context.phone.tolist();         }     } } } 

and in class want use it:

namespace sample_table { public partial class webform1 : system.web.ui.page {     protected void page_load(object sender, eventargs e)     {         classdal obj = new classdal();         obj.getall();          gridview1.datasource = obj;         gridview1.databind();     } } } 

but receive exception:

data source invalid type. must either ilistsource, ienumerable, or idatasource.

use tolist() extension method convert query list of items.

classdal obj = new classdal(); list<phone> list = obj.getall(); gridview1.datasource = list.tolist(); 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -