Reputation: 61
this is the first time i try asp.net programming so i face this problem:
i have several services that i need to communicate with and retrieve info from.... this info need to be shown to the client.
i decided to use a GridView control to display my data
Why do i need a grid view?
i need a gridview to view a List that i retrieve from a remote web service. i read that the grid view is the best choice there is to displaying data,, better than the Table and better from The Letteral control....
What is the problem?
i cant find a way to bind the GridView with my object,, although i set the gridview.datasource = List///// gridview.databind()
but it didnt work.
in this section i have more than one question:
another point is that i tested the allow sorting and allow paging on the grid view when i test it on a data from my database using ajax but it didnt work?????
any one can help i spend a very long time trying to solve the problem,, with no luck
this is the code am using
List<Car> test = BL.carFilterOnYearofmanuf(1980);
GridView1.DataSource = test;
GridView1.DataBind();
Upvotes: 2
Views: 3107
Reputation: 61
i might have missed out an important information about the error mesg i had it was:
"The data source for GridView with id 'GridView1' did not have any properties or attributes from which to generate columns. Ensure that your data source has content."
and i fixed the problem by changing the fields in my (Car) class into attributes:
public int Id;
to
public int Id{ get; set; }
and this problem was fixed,,, i didnt solve the sorting nor paging problem yet
Upvotes: 4
Reputation: 5028
To answer 1 of your points:
1) Your correct, you can simply bind to the griview using the following code:
Gridview1.datasource = List;
Gridview1.databind();
List needs to be one of the following types (taken from the MSDN documentation)
On your other point, I personally use the Jquery tablesorter plugin to do sorting on gridviews, and find it very good for sorting.
Upvotes: 0