C# – reason behind GridView in ASP.NET

asp.netc

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?

Best Answer

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 queries 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 of 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.