How to Implemented Bind Records in MVC4 using Sqlserver Aspx Gridview


In this Article, I am going to explain about How to Implemented Bind Records in MVC4 using Sqlserver Aspx Gridview. I have implemented Bind Records in MVC4 From Sqlserver With Aspx Gridview then Binded using View(ASPX). I have post source which is given below.

How to Bind Records using MVC4 from Sql server to Aspx Gridview



MVC have 2 Types of View

1Razor View
2.Aspx View

Razor View :- We must use Html Controls Only
Aspx View :- We can use Html and Aspx Contols . We can use Both.

In this Article I have Explain How to bind Records in MVC4 from Sqlserver in Aspx Gridview. Here I explain how to bind records using View


Step 1
How to Create Mvc4 Project For Aspx View.I have attached Images Given Below.
Step 2
How to Create Mvc4 Project Select Project view Aspx or Razor View .I have attached Images Given Below.
Step 3
How to Create Mvc4 Project Select View type Aspx Or Razor View.I have attached Images Given Below.

How to Refer Namespace using View
<%@ Import Namespace="System.Data"%>

I have paste the View code like this for Bind Records in Aspx Gridview from Sql server using Aspx View.How to Get Records from Sql Server and Established Connection Filling the Datatable using View


<p>
<%: Html.ActionLink("Create New", "Create") %>
</p>



<% System.Data.DataTable Dt=new System.Data.DataTable(); %>
<% System.Data.SqlClient.SqlConnection sqlcon = new System.Data.SqlClient.SqlConnection("Data source=PC-NAME;Initial Catalog=Test;Integrated security=True;"); %>
<% System.Data.SqlClient.SqlDataAdapter sqladp; %>
<% sqladp = new System.Data.SqlClient.SqlDataAdapter("Select * from TblEmp", sqlcon); %>
<% sqladp.Fill(Dt); %>
<% Grd1.DataSource=Dt; %>
<% Grd1.DataBind(); %>
<form id="frm1" runat ="server">
<asp:GridView ID="Grd1" runat ="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lbl1" runat ="server" Text ='<%# Eval("Id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField ="EmpName" HeaderText ="EmpName" />

<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="Txtamount" runat ="server" Text ='<%# Eval("EmpNo") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>

</Columns>
</asp:GridView>
</form>


Attachments

Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: