mo3az
mo3az

Reputation: 61

GridView problems

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:

  1. do i have to do the binding between the grid view and the car list in the code (c#) or do is it better to do it in the Markup ? and how can i make such a binding?
  2. when i used the raw DataSet from the webservice it worked just fine .... but i dont think the better way is to use the data set,,, and that is way i used the encapsulation so i dont know if it is better or not (silly 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

Answers (2)

mo3az
mo3az

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

Sean Taylor
Sean Taylor

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)

  • A DataTable
  • A DataView
  • A DataSet
  • A DataViewManager
  • Any component that implements the IListSource interface
  • Any component that implements the IList interface

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

Related Questions