Article Author : Tauseef Ahmad, Article Posted on : 9/18/2017, Article Category : Asp.net
Here i have explained with an example and attached code that how to retrieve (get) Record from sql server database and show in asp.net gridview with paging in c# and in previous article i explained how to save (insert) data in database using asp.net c#
i am explaining with very easy step by step process with screenshots and code provided.
Step 1. Open SQL Server Go to database and open Table (Student) All this step has been done in previous Article
Student Table with records in screenshot
Visual Studio Portion:
Step 2. Now open visual studio ( i used vs 2013 ) and create new empty website just see the screenshot.
now give name to website and click OK.
Step 3. now copy and add the following code in web.config file.
in connectionstring give your datasource name as i gave my own and you give your datasource name and also in database give your database name.
in case your sql server need sql authentication (userid and password ) than just use the following code other wise in window authentication use above code.
Now add new file (aspx)
give name to a page.
Add the following code to aspx page this code is used for show Record in gridview with paging to end user. GridView is one of the most common tools for displaying data in a grid format in ASP.NET.
in the above code asp.net gridview has some properties AllowPaging. Paging is very important When the data becomes large,paging helps the users to view chunks of data and also increases Page load time.
now if you want to give design to grid Go to page design mode and click on the small arrow shows in screenshot and than select auto format a popup window will open than select any design. some extra code will be automatically added to grid.
Code Behind Portion:
import the following namespaces.
Now create a method to get record from sql server and bind with gridview datasource.
Implementing paging in gridview. when a page is changed inside gridview the following event handler will executed.
Finally bind the grid method in pageload event whenever page loaded Record will be shown.
Now Run the Page and enjoy the gridview control power.
get record, retrieve record, asp.net gridview, paging