Custom Paging In Asp.Net Using Stored Procedure In Gridview

MVC3 ASP. Net Simple Db. Context Class to Connect to SQL Server Database. MVC3 ASP. Net DBContext Connection. Simple DBContext to Connect to SQL Server Database Table. This article describes how to create a simple MVC3 Project in Visual Web Developer 2. Express and use a simple connection string, Model class, and DBContext class to populate the Controller and View with data from SQL Server. Create a Table in SQL Server. CREATE TABLE dbo. Adv. ItemsId int NOT NULL PRIMARY KEY CLUSTERED,AType nvarchar5. NULL,AName nvarchar2. NULL. Populate it with some data. Creating the MVC3 ASP. Net Application. In Visual Studio 2. ASP. Net MVC 3 Web Application. Select Internet Application and click OK. Adding MVC3 Models to the Project. Click Add New Item to add the Model to the Models folder. Type in the name of the class and click OK. Add the code for the Model, Adv. Custom Paging In Asp.Net Using Stored Procedure In Gridview' title='Custom Paging In Asp.Net Using Stored Procedure In Gridview' />Custom Paging In Asp.Net Using Stored Procedure In GridviewItem. The names of collection should be the same as the names of the columns in the table. Mvc. Simple. DB. Modelspublic class Adv. Itemspublic virtual int ID get set public virtual string AType get set public virtual string AName get set. Adding the MVC3 Db. Context Class to the Data Layer. Add a new folder named DAL Data Access Layer and click Add New Item to add a Context class to it. In the code for the DBContext Model in the DAL folder, add the following using statements to the top using Mvc. Simple. DB. Models using System. Data. Entity. Add this code to the class so that it inherits from the Db. This tutorial will show you how to use Custom Objects to Insert to a SQL Server Database using C. In this tutorial, we are going to look at how we can create our. I have two Stored Procedures which are returning two sets of related data. The Data is like this. Openx Configuration File. First Procedure returns data like this ISSUEID ISSUETYPE. Interested in learning more about ASP. NET Articles from Around the Web Use MvcContrib Grid to Display a Grid of Data in ASP. NET MVC March 16th. ASP. NET Data Sources Free ASP. NET Tutorials, Reference Manual, and Quick Guide for Beginners. Learn ASP. NET starting from Environment Setup, Basic Controls. This article, by Scott Mitchell, examines how to efficiently page large data sets using custom paging with SQL Server 2005s new ROWNUMBER feature. Context Class. public class Adv. Items. Context Db. Contextpublic Db. Setlt Adv. Items Adv. Item. Pkg get set. In the Web. config file, add the Connection String. Name it the same as the class created in the DBContext file just created. Adv. Items. Context connection. StringServerYour. SQLServerSQLEXPRESS DatabaseDatabase. Integrated SecurityTrue provider. NameSystem. Data. Sql. Client. Adding the MVC3 Controller Build the Mvc Project to ensure that the classes will be known to the controller when it is created next. Right click on the Controller folder and click Add Controller. Name it lt Class. Name Controller. In this case, Adv. Items. Controller. Add these using statements to the top. Mvc. Simple. DB. DAL using Mvc. Simple. DB. Models. In the Controller code file, add this code to create an instance of the Db. Context class and return the collection in the Action. IdGBE/VBRR2Fj23lI/AAAAAAAAWCc/n5J3fpswuLc/s640/CustomPagerTemplate.gif' alt='Custom Paging In Asp.Net Using Stored Procedure In Gridview' title='Custom Paging In Asp.Net Using Stored Procedure In Gridview' />Result Index method to the View. Mvc. Simple. DB. Controllerspublic class Adv. Zp-aYblaq2I/hqdefault.jpg' alt='Custom Paging In Asp.Net Using Stored Procedure In Gridview' title='Custom Paging In Asp.Net Using Stored Procedure In Gridview' />Items. Controller Controllerprivate Adv. Items. Context db new Adv. Items. Context  public Action. Result Indexvar adv. Items db. Adv. Item. Pkg return Viewadv. Items. To. List. Adding the MVC3 View. Right click in the Controller next to the Action. Result Index to Add View. Select the Model Class and the Layout page. The Model will be the 1st one created with the field names, not the Context class. Add code to the View in Index. This article will demonstrate, the new feature of GridView Control in ASP. NET 4. 5. It adds a table to the rendered page and iterates through the collection to build the rows using Razor syntax and Linq Expressions with the data fields. IEnumerablelt Mvc. Simple. DB. Models. Adv. Items View. Bag. Title Adventure Items Layout ViewsSharedLayout. Adventure Itemslt h. IDlt th lt th. Mvc. Simple. DB. Models. Adv. Items item in Modellt tr lt td item. ID lt td lt td Html. Display. Formodel. Item item. ATypelt td lt td Html. Display. Formodel. Item item. ANamelt td lt tr lt table. Add to the code in the Layout. Adventure items page. Html. Action. LinkAdventures, Index, Adv. Itemslt li. Build the Project and then run the application. Click on the Adventures tab when the Index page opens.