Introduction : This is a simple ASP.NET MVC application that shows bound data on a Gridview through a database. This is simple application for beginners to learn how to create the database in MVC ASP.NET application and bind the data on Gridview. The MVC (Model-View-Controller) architecture is a way of decomposing an application into three parts the model, the view and the controller. It was originally applied in the graphical userinteraction model of input, processing and output. A model represents an application data and contains the logic for accessing and manipulating that data. The view is responsible for rendering the state of the model. The controller is responsible for intercepting and translating user input into actions to be performed by the model. Some simple steps to bind the data on a Gridview in a MVC ASP.NET that is given below.
Step 1:
Step 2 :
Step 3 :
Step 4 : After adding the Sql Server Database two file create in folder.
Step 5 :
Step 6 : If you want to set the Primary key and Relationship.
Step 7 :
Step 8 :
Code: <%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Index</title> </head> <body style="height: 106px" bgcolor="#66ffcc"> <form id="form1" runat="server"> <div style="background-color: #CC6699"> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"> <Columns> <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /> <asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" /> <asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" /> <asp:BoundField DataField="salary" HeaderText="salary" SortExpression="salary" /> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [Name], [Id], [Address], [salary] FROM [Employee]"> </asp:SqlDataSource> </tr> </div> </form> </body> </html> Step 9 : Press crtl+f5 run the program.
Output:
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: