DetailsView Control displays each field of a single data as HTML table and ability to insert, update, and delete single record at a time. DetailsView Control support page forward and backward traversing. We can apply following style properties on DetailsView Control are:
- RowStyle
- HeaderStyle
- CommandRowStyle
DetailsView Control does not support a selection event.
Here’s an example.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" AllowPaging="true"
OnPageIndexChanging="DetailsView1_PageIndexChanging">
</asp:DetailsView>
</div>
</form>
</body>
</html>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DetailsView1.DataSource = DisplayRecords();
DetailsView1.DataBind();
}
}
public List<Patient> DisplayRecords()
{
List<Patient> Obj = new List<Patient>();
Obj.Add(new Patient() { FullName = "ABBEY", Age = 25, BloodGroup = "A+", Gender = "Male" });
Obj.Add(new Patient() { FullName = "Wilmer–Zenith", Age = 11, BloodGroup = "B+", Gender = "Male" });
Obj.Add(new Patient() { FullName = "Stockton–Tay", Age = 10, BloodGroup = "O", Gender = "Male" });
Obj.Add(new Patient() { FullName = "Roman–Sadler", Age = 23, BloodGroup = "O", Gender = "Male" });
return Obj;
}
public class Patient
{
public String FullName { get; set; }
public int? Age { get; set; }
public string Gender { get; set; }
public string BloodGroup { get; set; }
}
protected void DetailsView1_PageIndexChanging(object sender, DetailsViewPageEventArgs e)
{
DetailsView1.PageIndex = e.NewPageIndex;
DetailsView1.DataSource = DisplayRecords();
DetailsView1.DataBind();
}
VB.NET
Protected Sub Page_Load(sender As Object, e As EventArgs)
If Not Page.IsPostBack Then
DetailsView1.DataSource = DisplayRecords()
DetailsView1.DataBind()
End If
End Sub
Public Function DisplayRecords() As List(Of Patient)
Dim Obj As New List(Of Patient)()
Obj.Add(New Patient() With { _
.FullName = "ABBEY", _
.Age = 25, _
.BloodGroup = "A+", _
.Gender = "Male" _
})
Obj.Add(New Patient() With { _
.FullName = "Wilmer–Zenith", _
.Age = 11, _
.BloodGroup = "B+", _
.Gender = "Male" _
})
Obj.Add(New Patient() With { _
.FullName = "Stockton–Tay", _
.Age = 10, _
.BloodGroup = "O", _
.Gender = "Male" _
})
Obj.Add(New Patient() With { _
.FullName = "Roman–Sadler", _
.Age = 23, _
.BloodGroup = "O", _
.Gender = "Male" _
})
Return Obj
End Function
Public Class Patient
Public Property FullName() As [String]
Get
Return m_FullName
End Get
Set(value As [String])
m_FullName = value
End Set
End Property
Private m_FullName As [String]
Public Property Age() As System.Nullable(Of Integer)
Get
Return m_Age
End Get
Set(value As System.Nullable(Of Integer))
m_Age = value
End Set
End Property
Private m_Age As System.Nullable(Of Integer)
Public Property Gender() As String
Get
Return m_Gender
End Get
Set(value As String)
m_Gender = value
End Set
End Property
Private m_Gender As String
Public Property BloodGroup() As String
Get
Return m_BloodGroup
End Get
Set(value As String)
m_BloodGroup = value
End Set
End Property
Private m_BloodGroup As String
End Class
Protected Sub DetailsView1_PageIndexChanging(sender As Object, e As DetailsViewPageEventArgs) Handles DetailsView1.PageIndexChanging
DetailsView1.PageIndex = e.NewPageIndex
DetailsView1.DataSource = DisplayRecords()
DetailsView1.DataBind()
End Sub
If you will set DetailsView AllowPaging="true”, you will see the following error message.
The DetailsView 'DetailsView1' fired event PageIndexChanging which wasn't handled.

To handle the paging with DetailsView Control, you also need to set DetailsView.PageIndexChanging Event
DetailsView Control supported in .Net Framework version 2.0, 3.0, 3 and 4.O
Output

Download
DetailsView.rar (1.01 kb)
See live demo