SlideShare a Scribd company logo
WELCOME TO MY PRESENTATION
Ms. A. Sakila., I Msc Cs
 DetailView is one of the important control, that
is mainly used in master-detail scenario.
 You select the record from master control (as
example GridView) and selected record is
displayed in DetailView control.
 In general GridView control displays more
than one record, but the DetailsView control
displays single record from database table.
 When you execute your web page, DetailsView
control renders an HTML table.The
DetailsView supports both declarative and
programmatic databinding.
 DetailsView control supports the edit, insert,
delete and paging functionality.
 Write down the connection string in web.config
file. Here Database name is Employee and table
name is tblEmps.
<configuration>
<connectionStrings>
<add name="conString" connectionString="Data
Source=(local);Initial Catalog =
Employee;Integrated Security=True" />
</connectionStrings>
</configuration>
Example
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.UI.WebControls;
using System.Web.UI;
public partial class Default : System.Web.UI.Page
{
SqlConnection conn;
SqlDataAdapter adapter;
DataSet ds;
SqlCommand cmd;
string cs =
ConfigurationManager.ConnectionStrings["con
String"].ConnectionString;
protected void Page_Load(object sender,
EventArgs e)
{
if (!IsPostBack)
{
PopulateDetailView();
}
}
protected void PopulateDetailView()
{
try
{
conn = new SqlConnection(cs);
adapter = new SqlDataAdapter("select *
from tblEmps", conn);
ds = new DataSet();
adapter.Fill(ds);
DetailsView1.DataSource = ds;
DetailsView1.DataBind();
}
 catch (Exception ex)
{
Label1.Text = "ERROR :: " + ex.Message;
}
}
protected void
DetailsView1_PageIndexChanging(object sender,
DetailsViewPageEventArgs e)
{
DetailsView1.PageIndex = e.NewPageIndex;
PopulateDetailView();
}
protected void DetailsView1_ModeChanging(object
sender, DetailsViewModeEventArgs e)
{
DetailsView1.ChangeMode(e.NewMode);
PopulateDetailView();
}
}
Output:
Default mode of DetailView control is ReadOnly.
You can change this default behavior by using
ChangeMode method.
 DetailsView1.ChangeMode(DetailsViewMode.Edit
);
DetailsViewMode is an enaum type that supports
the following options.
Edit
 Insert
 ReadOnly
 In DetailView paging is not enabled by default. For
achieve paging set AllowPaging property as True.
 If user clicks on paging link at bottom of DetailView
control, then PageIndexChanging event fires.
 Another important property of DetailView control is
PagerSettings.
 This property is used to customize the look of the
paging interface.
 For example, you can display first, previous, next, and
last links instead of page numbers in DetailView.
 User can also update the existing database
records. DetailsView control has the properety
AutoGenerateEditButton.
 In order to update a record, set the value of
AutoGenerateEditButton property as true.
 The AutoGenerateEditButton property
automatically generates the Edit link at the bottom
of DetailView control.
 Next provide the value of DataKeyNames
property. The DataKeyNames property holds the
name of the primary key column of database table.
 If you do not assign value in DataKeyNames
property,
 then you will not get the primary key for
performing updating or deleting the record.
 When user click on "Edit" link, update and
cancel link will appears in-place of edit link.

 When user clicks on "Edit" link, ItemUpdating
event fires.
protected void DetailsView1_ItemUpdating(object
sender, DetailsViewUpdateEventArgs e )
{
int ID =
Convert.ToInt32(DetailsView1.Rows[0].Cells[1].Text);
TextBox txtName =
DetailsView1.Rows[1].Cells[1].Controls[0] as TextBox;
TextBox txtGender =
DetailsView1.Rows[2].Cells[1].Controls[0] as TextBox;
TextBox txtSalary =
DetailsView1.Rows[3].Cells[1].Controls[0] as TextBox;
TextBox txtAddress =
DetailsView1.Rows[4].Cells[1].Controls[0] as TextBox;
TextBox txtDepartmentID =
DetailsView1.Rows[5].Cells[1].Controls[0] as TextBox;
string updateQuery = "update tblEmps set name='" +
txtName.Text + "',gender='"
+ txtGender.Text + "',Salary=" + txtSalary.Text +
",Address='" + txtAddress.Text + "',DepID="
+ txtDepartmentID.Text + " where
EmpID=" + ID;
conn = new SqlConnection(cs);
cmd = new SqlCommand(updateQuery,
conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
DetailsView1.ChangeMode(DetailsViewMode
.ReadOnly);
PopulateDetailView();
}
When you perform edit operation, then by default you will not get any type of validation. You cannot restrict the user to enter nul
 You cannot restrict the user to enter null values or
illegal value.
 If you need to provide validation with input data,
then you should use templates with the
DetailsView control.
<Fields>
<asp:TemplateField HeaderText="Title:">
<EditItemTemplate>
<asp:TextBox id="txtName" Text='<%#
Bind("Name") %>' runat="server" />
<asp:RequiredFieldValidator id="reqName"
ControlToValidate=" txtName "
Text="(required)" Display="Dynamic"
Runat="server" />
</EditItemTemplate>
</asp:TemplateField>
</Fields>
 For inserting the new record into the database, first
set the value of AutoGenerateInsertButton
property as True.
 It will automatically generate the "New" link at
the bottom of DetailView control.
 When you click on the new link of DetailView
control, the UI will be changed and blank editable
text will appear.
 Now you have to find these textbox control that is
available inside the DetailView control.
 For inserting the record in database table, write the code in "ItemInserting" event as
given below.
protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs
e)
{
TextBox txtEmpID = DetailsView1.Rows[0].Cells[1].Controls[0] as TextBox;
TextBox txtName = DetailsView1.Rows[1].Cells[1].Controls[0] as TextBox;
TextBox txtGender = DetailsView1.Rows[2].Cells[1].Controls[0] as TextBox;
TextBox txtSalary = DetailsView1.Rows[3].Cells[1].Controls[0] as TextBox;
TextBox txtAddress = DetailsView1.Rows[4].Cells[1].Controls[0] as TextBox;
TextBox txtDepartmentID = DetailsView1.Rows[5].Cells[1].Controls[0] as TextBox;
string insertQuery = "insert into tblEmps
values("+txtEmpID.Text+",'"+txtName.Text+"',
'"+txtGender.Text+"',"+txtSalary.Text+",'"+txtAddress.Text+"',"+txtDepartmentI
D.Text+")";
conn = new SqlConnection(cs);
cmd = new SqlCommand(insertQuery, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
PopulateDetailView();
}
 For enabling delete functionality with the DetailsView control, set
the value AutoGenerateDeleteButton property as true. It will
automatically generate the "Delete" link at the bottom of
DetailView control.
protected void DetailsView1_ItemDeleting(object sender,
DetailsViewDeleteEventArgs e)
{
int ID =
Convert.ToInt32(DetailsView1.Rows[0].Cells[1].Text);
string deleteQuery = "delete tblEmps where empid = "+ID;
conn = new SqlConnection(cs);
cmd = new SqlCommand(deleteQuery, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
PopulateDetailView();
}
Detail view in distributed technologies

More Related Content

PDF
Step by Step Asp.Net GridView Tutorials
PDF
Data Binding and Data Grid View Classes
PPSX
06 asp.net session08
PPTX
ASP.NET Lecture 4
PPTX
Grid View Control CS
PPT
ASP.NET 10 - Data Controls
PDF
FiletodbAdapters
DOCX
Simple ado program by visual studio
Step by Step Asp.Net GridView Tutorials
Data Binding and Data Grid View Classes
06 asp.net session08
ASP.NET Lecture 4
Grid View Control CS
ASP.NET 10 - Data Controls
FiletodbAdapters
Simple ado program by visual studio

What's hot (16)

PPTX
Mysql: Tools & Gui
PPS
06 asp.net session08
PPT
Chapter12 (1)
PDF
Backendless apps
DOC
exa_cer_g23
PPTX
Data Binding - Android by Harin Trivedi
PPTX
SharePoint Conference 2018 - APIs, APIs everywhere!
PPTX
React outbox
PDF
RubyOnRails-Cheatsheet-BlaineKendall
PPTX
APIs, APIs Everywhere!
PPTX
ASP.NET - Life cycle of asp
ODP
Android App Development - 04 Views and layouts
PPT
SetFocus SQL Portfolio
PPTX
Schema webinar
PDF
CaseStudy-MohammedImranAlam-Xcelsius
Mysql: Tools & Gui
06 asp.net session08
Chapter12 (1)
Backendless apps
exa_cer_g23
Data Binding - Android by Harin Trivedi
SharePoint Conference 2018 - APIs, APIs everywhere!
React outbox
RubyOnRails-Cheatsheet-BlaineKendall
APIs, APIs Everywhere!
ASP.NET - Life cycle of asp
Android App Development - 04 Views and layouts
SetFocus SQL Portfolio
Schema webinar
CaseStudy-MohammedImranAlam-Xcelsius
Ad

Similar to Detail view in distributed technologies (20)

PPTX
form view
PPTX
Disconnected data
DOCX
Grid view control
PPTX
Application of Insert and select notes.ppt x
PPTX
PDF
DotNet Slip Solution_All_2019Pattern.pdf
DOCX
Add row in asp.net Gridview on button click using C# and vb.net
DOCX
Add row in asp.net Gridview on button click using C# and vb.net
DOCX
This is part 1 of 3STEP 1 Modify the clsDataLayer to Use a Two-St.docx
PPT
ASP.NET Session 13 14
DOC
Cis407 a ilab 4 web application development devry university
DOCX
Cis 407 i lab 5 of 7
PPTX
Grid Vew Control VB
DOCX
Cis 407 i lab 4 of 7
PPT
Fixing an annoying GridView problem
PPTX
76.pptx ajx ppt file for univercity of granted
PDF
Entity frame work by Salman Mushtaq -1-
PPTX
form view
Disconnected data
Grid view control
Application of Insert and select notes.ppt x
DotNet Slip Solution_All_2019Pattern.pdf
Add row in asp.net Gridview on button click using C# and vb.net
Add row in asp.net Gridview on button click using C# and vb.net
This is part 1 of 3STEP 1 Modify the clsDataLayer to Use a Two-St.docx
ASP.NET Session 13 14
Cis407 a ilab 4 web application development devry university
Cis 407 i lab 5 of 7
Grid Vew Control VB
Cis 407 i lab 4 of 7
Fixing an annoying GridView problem
76.pptx ajx ppt file for univercity of granted
Entity frame work by Salman Mushtaq -1-
Ad

Recently uploaded (20)

DOCX
ENGLISH PROJECT FOR BINOD BIHARI MAHTO KOYLANCHAL UNIVERSITY
PPTX
Intro to ISO 9001 2015.pptx wareness raising
DOC
学位双硕士UTAS毕业证,墨尔本理工学院毕业证留学硕士毕业证
PPTX
INTERNATIONAL LABOUR ORAGNISATION PPT ON SOCIAL SCIENCE
PPTX
Primary and secondary sources, and history
PDF
Instagram's Product Secrets Unveiled with this PPT
PPTX
Relationship Management Presentation In Banking.pptx
PPTX
Tour Presentation Educational Activity.pptx
PPTX
worship songs, in any order, compilation
PDF
Swiggy’s Playbook: UX, Logistics & Monetization
PPT
First Aid Training Presentation Slides.ppt
PPTX
AcademyNaturalLanguageProcessing-EN-ILT-M02-Introduction.pptx
PPTX
An Unlikely Response 08 10 2025.pptx
PPTX
Effective_Handling_Information_Presentation.pptx
PPT
The Effect of Human Resource Management Practice on Organizational Performanc...
PPTX
Hydrogel Based delivery Cancer Treatment
PPTX
MERISTEMATIC TISSUES (MERISTEMS) PPT PUBLIC
PPTX
The Effect of Human Resource Management Practice on Organizational Performanc...
PPTX
Impressionism_PostImpressionism_Presentation.pptx
PDF
Tunisia's Founding Father(s) Pitch-Deck 2022.pdf
ENGLISH PROJECT FOR BINOD BIHARI MAHTO KOYLANCHAL UNIVERSITY
Intro to ISO 9001 2015.pptx wareness raising
学位双硕士UTAS毕业证,墨尔本理工学院毕业证留学硕士毕业证
INTERNATIONAL LABOUR ORAGNISATION PPT ON SOCIAL SCIENCE
Primary and secondary sources, and history
Instagram's Product Secrets Unveiled with this PPT
Relationship Management Presentation In Banking.pptx
Tour Presentation Educational Activity.pptx
worship songs, in any order, compilation
Swiggy’s Playbook: UX, Logistics & Monetization
First Aid Training Presentation Slides.ppt
AcademyNaturalLanguageProcessing-EN-ILT-M02-Introduction.pptx
An Unlikely Response 08 10 2025.pptx
Effective_Handling_Information_Presentation.pptx
The Effect of Human Resource Management Practice on Organizational Performanc...
Hydrogel Based delivery Cancer Treatment
MERISTEMATIC TISSUES (MERISTEMS) PPT PUBLIC
The Effect of Human Resource Management Practice on Organizational Performanc...
Impressionism_PostImpressionism_Presentation.pptx
Tunisia's Founding Father(s) Pitch-Deck 2022.pdf

Detail view in distributed technologies

  • 1. WELCOME TO MY PRESENTATION Ms. A. Sakila., I Msc Cs
  • 2.  DetailView is one of the important control, that is mainly used in master-detail scenario.  You select the record from master control (as example GridView) and selected record is displayed in DetailView control.  In general GridView control displays more than one record, but the DetailsView control displays single record from database table.
  • 3.  When you execute your web page, DetailsView control renders an HTML table.The DetailsView supports both declarative and programmatic databinding.  DetailsView control supports the edit, insert, delete and paging functionality.  Write down the connection string in web.config file. Here Database name is Employee and table name is tblEmps.
  • 4. <configuration> <connectionStrings> <add name="conString" connectionString="Data Source=(local);Initial Catalog = Employee;Integrated Security=True" /> </connectionStrings> </configuration> Example using System; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Web.UI.WebControls; using System.Web.UI; public partial class Default : System.Web.UI.Page
  • 5. { SqlConnection conn; SqlDataAdapter adapter; DataSet ds; SqlCommand cmd; string cs = ConfigurationManager.ConnectionStrings["con String"].ConnectionString; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack)
  • 6. { PopulateDetailView(); } } protected void PopulateDetailView() { try { conn = new SqlConnection(cs); adapter = new SqlDataAdapter("select * from tblEmps", conn); ds = new DataSet(); adapter.Fill(ds); DetailsView1.DataSource = ds; DetailsView1.DataBind(); }
  • 7.  catch (Exception ex) { Label1.Text = "ERROR :: " + ex.Message; } } protected void DetailsView1_PageIndexChanging(object sender, DetailsViewPageEventArgs e) { DetailsView1.PageIndex = e.NewPageIndex; PopulateDetailView(); } protected void DetailsView1_ModeChanging(object sender, DetailsViewModeEventArgs e) { DetailsView1.ChangeMode(e.NewMode); PopulateDetailView(); } }
  • 8. Output: Default mode of DetailView control is ReadOnly. You can change this default behavior by using ChangeMode method.  DetailsView1.ChangeMode(DetailsViewMode.Edit ); DetailsViewMode is an enaum type that supports the following options. Edit  Insert  ReadOnly
  • 9.  In DetailView paging is not enabled by default. For achieve paging set AllowPaging property as True.  If user clicks on paging link at bottom of DetailView control, then PageIndexChanging event fires.  Another important property of DetailView control is PagerSettings.  This property is used to customize the look of the paging interface.  For example, you can display first, previous, next, and last links instead of page numbers in DetailView.
  • 10.  User can also update the existing database records. DetailsView control has the properety AutoGenerateEditButton.  In order to update a record, set the value of AutoGenerateEditButton property as true.  The AutoGenerateEditButton property automatically generates the Edit link at the bottom of DetailView control.  Next provide the value of DataKeyNames property. The DataKeyNames property holds the name of the primary key column of database table.
  • 11.  If you do not assign value in DataKeyNames property,  then you will not get the primary key for performing updating or deleting the record.  When user click on "Edit" link, update and cancel link will appears in-place of edit link.   When user clicks on "Edit" link, ItemUpdating event fires.
  • 12. protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e ) { int ID = Convert.ToInt32(DetailsView1.Rows[0].Cells[1].Text); TextBox txtName = DetailsView1.Rows[1].Cells[1].Controls[0] as TextBox; TextBox txtGender = DetailsView1.Rows[2].Cells[1].Controls[0] as TextBox; TextBox txtSalary = DetailsView1.Rows[3].Cells[1].Controls[0] as TextBox; TextBox txtAddress = DetailsView1.Rows[4].Cells[1].Controls[0] as TextBox; TextBox txtDepartmentID = DetailsView1.Rows[5].Cells[1].Controls[0] as TextBox; string updateQuery = "update tblEmps set name='" + txtName.Text + "',gender='" + txtGender.Text + "',Salary=" + txtSalary.Text + ",Address='" + txtAddress.Text + "',DepID="
  • 13. + txtDepartmentID.Text + " where EmpID=" + ID; conn = new SqlConnection(cs); cmd = new SqlCommand(updateQuery, conn); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); DetailsView1.ChangeMode(DetailsViewMode .ReadOnly); PopulateDetailView(); } When you perform edit operation, then by default you will not get any type of validation. You cannot restrict the user to enter nul
  • 14.  You cannot restrict the user to enter null values or illegal value.  If you need to provide validation with input data, then you should use templates with the DetailsView control. <Fields> <asp:TemplateField HeaderText="Title:"> <EditItemTemplate> <asp:TextBox id="txtName" Text='<%# Bind("Name") %>' runat="server" /> <asp:RequiredFieldValidator id="reqName" ControlToValidate=" txtName " Text="(required)" Display="Dynamic" Runat="server" /> </EditItemTemplate> </asp:TemplateField> </Fields>
  • 15.  For inserting the new record into the database, first set the value of AutoGenerateInsertButton property as True.  It will automatically generate the "New" link at the bottom of DetailView control.  When you click on the new link of DetailView control, the UI will be changed and blank editable text will appear.  Now you have to find these textbox control that is available inside the DetailView control.
  • 16.  For inserting the record in database table, write the code in "ItemInserting" event as given below. protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e) { TextBox txtEmpID = DetailsView1.Rows[0].Cells[1].Controls[0] as TextBox; TextBox txtName = DetailsView1.Rows[1].Cells[1].Controls[0] as TextBox; TextBox txtGender = DetailsView1.Rows[2].Cells[1].Controls[0] as TextBox; TextBox txtSalary = DetailsView1.Rows[3].Cells[1].Controls[0] as TextBox; TextBox txtAddress = DetailsView1.Rows[4].Cells[1].Controls[0] as TextBox; TextBox txtDepartmentID = DetailsView1.Rows[5].Cells[1].Controls[0] as TextBox; string insertQuery = "insert into tblEmps values("+txtEmpID.Text+",'"+txtName.Text+"', '"+txtGender.Text+"',"+txtSalary.Text+",'"+txtAddress.Text+"',"+txtDepartmentI D.Text+")"; conn = new SqlConnection(cs); cmd = new SqlCommand(insertQuery, conn); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); DetailsView1.ChangeMode(DetailsViewMode.ReadOnly); PopulateDetailView(); }
  • 17.  For enabling delete functionality with the DetailsView control, set the value AutoGenerateDeleteButton property as true. It will automatically generate the "Delete" link at the bottom of DetailView control. protected void DetailsView1_ItemDeleting(object sender, DetailsViewDeleteEventArgs e) { int ID = Convert.ToInt32(DetailsView1.Rows[0].Cells[1].Text); string deleteQuery = "delete tblEmps where empid = "+ID; conn = new SqlConnection(cs); cmd = new SqlCommand(deleteQuery, conn); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); DetailsView1.ChangeMode(DetailsViewMode.ReadOnly); PopulateDetailView(); }