Thursday, March 24, 2011

What is reason behind GridView in ASP.NET?

I have confusion about GridView in ASP.NET.

How does the GridView exactly work?

I mean when we bind data to gridview with 100 records through GridView1.DataBind();

I have set Pageindexchanging Event and I set the Pagesize = "40" and AllowPaging="True" Then....

Now the interesting part is begins What happens when i Click on next page index of GridView is it. Once again go to the database and fetch the data.. or gridview creates its own dataset and fetch data from that dataset or anything different than this...

And one more thing is how the Sorting works in GridView?

From stackoverflow
  • This article takes a pretty exhaustive look at the gridview.

  • The simple answer is yes, the GridView is simply a view placed over a DataGrid, and all the parameters specified affect how the GridView is rendered for the user. Since we're dealing with the stateless web, you will have to rebind the data.

    One trick for this is that if your dataset isn't too large, you can store the DataTable in the user's session and simply retrieve it from there, saving a trip to the database. If you are dealing with a large amount of data, then you'll want to look into options for having your SQL quereis function in a "paged" format so you only retrieve the rows you intend to display.

    With Paging and Sorting, they serve as an event to respond to in which you resort your data and rebind to the grid for presentation.

    The advantage to the GridView is that you do have a central object with a lot of functionality built in that you can use for rapid deployment. When you get a hand of how the sorting, paging, row commands, and other things work, you can do some really great things in a small amount of code.

  • It depends what your data source is, if your datasource supports paging, then it will fetch only the records it needs to show that page, if it does not, it will get all the records and discard the one you don't want. For both examples, it will talk to the datasource everytime you change page.

    See here for more details: http://msdn.microsoft.com/en-us/library/5aw1xfh3.aspx

0 comments:

Post a Comment