Record should be displayed from the database in both the controls.
Answer:
DetailView vs FormView:
The DetailView and FormView controls enable us to display a single data item i.e. a single database record at a time. Both the controls help us perform insert, update, delete and select operation on the database with single data item.
Introduction:
In this application we are use DetailView and FormView controls to display the record from the database. Both the controls are used to display only single record at a time.
Steps to develop this application
1. Create a table “StudentMaster”
create table StudentMaster (studID int, studName varchar(50), DOB date, Percentage float, courseName varchar(20), Address varchar(100))
2. Develop the web page in vb.net
detailviewVsformview.aspx
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Configuration" %>
<script language="VB" runat="server" Debug="true">
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Me.BindData()
End If
End Sub
Sub BindData()
Dim constr As String = ConfigurationSettings.AppSettings("ConnectionString")
Using oConn As New SqlConnection(constr)
Dim cmd As New SqlCommand("select * from StudentMaster")
Dim sda As New SqlDataAdapter()
cmd.Connection = oConn
sda.SelectCommand = cmd
Dim dt As New DataTable()
sda.Fill(dt)
FormView1.DataSource = dt
formview1.DataBind()
detailview.DataSource = dt
detailview.DataBind()
End Using
End Sub
</script>
<body>
<form id="form1" runat="server">
<div>
<h2><i><u>Record to DetailView Control</u></i></h2>
<asp:DetailsView ID="detailview" runat="server" Width="275px">
</asp:DetailsView>
<h2><i><u>Record to FormView Control</u></i></h2>
<asp:FormView ID="formview1" runat="server" AutoGenerateColumns="false" AllowPaging ="true">
<ItemTemplate>
<b><%#Eval("studName")%></b>  
<b><%#Eval("DOB", "{0:MM/dd/yyyy}")%></b>  
<b><%#Eval("courseName")%></b>  
<b><%#Eval("Address")%></b>
</ItemTemplate>
</asp:FormView>
</div>
</form>
</body>
</html>
Output:



