SlideShare a Scribd company logo
1 of 18
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

What's hot

06 asp.net session08
06 asp.net session0806 asp.net session08
06 asp.net session08Mani Chaubey
 
Data Binding - Android by Harin Trivedi
Data Binding - Android by Harin TrivediData Binding - Android by Harin Trivedi
Data Binding - Android by Harin Trivediharintrivedi
 
SharePoint Conference 2018 - APIs, APIs everywhere!
SharePoint Conference 2018 - APIs, APIs everywhere!SharePoint Conference 2018 - APIs, APIs everywhere!
SharePoint Conference 2018 - APIs, APIs everywhere!Sébastien Levert
 
RubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendallRubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendalltutorialsruby
 
APIs, APIs Everywhere!
APIs, APIs Everywhere!APIs, APIs Everywhere!
APIs, APIs Everywhere!BIWUG
 
ASP.NET - Life cycle of asp
ASP.NET - Life cycle of aspASP.NET - Life cycle of asp
ASP.NET - Life cycle of asppriya Nithya
 
Android App Development - 04 Views and layouts
Android App Development - 04 Views and layoutsAndroid App Development - 04 Views and layouts
Android App Development - 04 Views and layoutsDiego Grancini
 
SetFocus SQL Portfolio
SetFocus SQL PortfolioSetFocus SQL Portfolio
SetFocus SQL Portfoliogeometro17
 
CaseStudy-MohammedImranAlam-Xcelsius
CaseStudy-MohammedImranAlam-XcelsiusCaseStudy-MohammedImranAlam-Xcelsius
CaseStudy-MohammedImranAlam-XcelsiusMohammed Imran Alam
 

What's hot (16)

Mysql: Tools & Gui
Mysql: Tools & GuiMysql: Tools & Gui
Mysql: Tools & Gui
 
06 asp.net session08
06 asp.net session0806 asp.net session08
06 asp.net session08
 
Chapter12 (1)
Chapter12 (1)Chapter12 (1)
Chapter12 (1)
 
Backendless apps
Backendless appsBackendless apps
Backendless apps
 
exa_cer_g23
exa_cer_g23exa_cer_g23
exa_cer_g23
 
Data Binding - Android by Harin Trivedi
Data Binding - Android by Harin TrivediData Binding - Android by Harin Trivedi
Data Binding - Android by Harin Trivedi
 
SharePoint Conference 2018 - APIs, APIs everywhere!
SharePoint Conference 2018 - APIs, APIs everywhere!SharePoint Conference 2018 - APIs, APIs everywhere!
SharePoint Conference 2018 - APIs, APIs everywhere!
 
React outbox
React outboxReact outbox
React outbox
 
RubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendallRubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendall
 
Vb & asp .net
Vb & asp .netVb & asp .net
Vb & asp .net
 
APIs, APIs Everywhere!
APIs, APIs Everywhere!APIs, APIs Everywhere!
APIs, APIs Everywhere!
 
ASP.NET - Life cycle of asp
ASP.NET - Life cycle of aspASP.NET - Life cycle of asp
ASP.NET - Life cycle of asp
 
Android App Development - 04 Views and layouts
Android App Development - 04 Views and layoutsAndroid App Development - 04 Views and layouts
Android App Development - 04 Views and layouts
 
SetFocus SQL Portfolio
SetFocus SQL PortfolioSetFocus SQL Portfolio
SetFocus SQL Portfolio
 
Schema webinar
Schema webinarSchema webinar
Schema webinar
 
CaseStudy-MohammedImranAlam-Xcelsius
CaseStudy-MohammedImranAlam-XcelsiusCaseStudy-MohammedImranAlam-Xcelsius
CaseStudy-MohammedImranAlam-Xcelsius
 

Similar to Detail view in distributed technologies

Learn about dot net attributes
Learn about dot net attributesLearn about dot net attributes
Learn about dot net attributessonia merchant
 
Cis407 a ilab 6 web application development devry university
Cis407 a ilab 6 web application development devry universityCis407 a ilab 6 web application development devry university
Cis407 a ilab 6 web application development devry universitylhkslkdh89009
 
Data controls ppt
Data controls pptData controls ppt
Data controls pptIblesoft
 
ASP.NET 03 - Working With Web Server Controls
ASP.NET 03 - Working With Web Server ControlsASP.NET 03 - Working With Web Server Controls
ASP.NET 03 - Working With Web Server ControlsRandy Connolly
 
AdRotator and AdRepeater Control in Asp.Net for Msc CS
AdRotator and AdRepeater Control in Asp.Net for Msc CSAdRotator and AdRepeater Control in Asp.Net for Msc CS
AdRotator and AdRepeater Control in Asp.Net for Msc CSThanveen
 
Cis 407 i lab 5 of 7
Cis 407 i lab 5 of 7Cis 407 i lab 5 of 7
Cis 407 i lab 5 of 7helpido9
 
Disconnected data
Disconnected dataDisconnected data
Disconnected dataaspnet123
 
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docx
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docxLab StepsSTEP 1 Login Form1. In order to do this lab, we need.docx
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docxsmile790243
 
Learning .NET Attributes
Learning .NET AttributesLearning .NET Attributes
Learning .NET AttributesPooja Gaikwad
 
Learn dot net attributes
Learn dot net attributesLearn dot net attributes
Learn dot net attributessonia merchant
 

Similar to Detail view in distributed technologies (20)

form view
form viewform view
form view
 
GRID VIEW PPT
GRID VIEW PPTGRID VIEW PPT
GRID VIEW PPT
 
Learn about dot net attributes
Learn about dot net attributesLearn about dot net attributes
Learn about dot net attributes
 
Cis407 a ilab 6 web application development devry university
Cis407 a ilab 6 web application development devry universityCis407 a ilab 6 web application development devry university
Cis407 a ilab 6 web application development devry university
 
Data controls ppt
Data controls pptData controls ppt
Data controls ppt
 
ASP.NET 03 - Working With Web Server Controls
ASP.NET 03 - Working With Web Server ControlsASP.NET 03 - Working With Web Server Controls
ASP.NET 03 - Working With Web Server Controls
 
Dev308
Dev308Dev308
Dev308
 
Android interface elements and controls-chapter8
Android interface elements and controls-chapter8Android interface elements and controls-chapter8
Android interface elements and controls-chapter8
 
Chapter 16
Chapter 16Chapter 16
Chapter 16
 
The most basic inline tag
The most basic inline tagThe most basic inline tag
The most basic inline tag
 
Ch 7 data binding
Ch 7 data bindingCh 7 data binding
Ch 7 data binding
 
Chapter 6
Chapter 6Chapter 6
Chapter 6
 
AdRotator and AdRepeater Control in Asp.Net for Msc CS
AdRotator and AdRepeater Control in Asp.Net for Msc CSAdRotator and AdRepeater Control in Asp.Net for Msc CS
AdRotator and AdRepeater Control in Asp.Net for Msc CS
 
Cis 407 i lab 5 of 7
Cis 407 i lab 5 of 7Cis 407 i lab 5 of 7
Cis 407 i lab 5 of 7
 
Disconnected data
Disconnected dataDisconnected data
Disconnected data
 
data binding.docx
data binding.docxdata binding.docx
data binding.docx
 
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docx
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docxLab StepsSTEP 1 Login Form1. In order to do this lab, we need.docx
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docx
 
Module05
Module05Module05
Module05
 
Learning .NET Attributes
Learning .NET AttributesLearning .NET Attributes
Learning .NET Attributes
 
Learn dot net attributes
Learn dot net attributesLearn dot net attributes
Learn dot net attributes
 

Recently uploaded

Russian Call Girls in Kolkata Vaishnavi 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Vaishnavi 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Vaishnavi 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Vaishnavi 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Simulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with AerialistSimulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with AerialistSebastiano Panichella
 
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...NETWAYS
 
Microsoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AIMicrosoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AITatiana Gurgel
 
LANDMARKS AND MONUMENTS IN NIGERIA.pptx
LANDMARKS  AND MONUMENTS IN NIGERIA.pptxLANDMARKS  AND MONUMENTS IN NIGERIA.pptx
LANDMARKS AND MONUMENTS IN NIGERIA.pptxBasil Achie
 
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Kayode Fayemi
 
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...henrik385807
 
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...NETWAYS
 
George Lever - eCommerce Day Chile 2024
George Lever -  eCommerce Day Chile 2024George Lever -  eCommerce Day Chile 2024
George Lever - eCommerce Day Chile 2024eCommerce Institute
 
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfOpen Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfhenrik385807
 
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfCTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfhenrik385807
 
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...NETWAYS
 
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Salam Al-Karadaghi
 
Motivation and Theory Maslow and Murray pdf
Motivation and Theory Maslow and Murray pdfMotivation and Theory Maslow and Murray pdf
Motivation and Theory Maslow and Murray pdfakankshagupta7348026
 
The 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringThe 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringSebastiano Panichella
 
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)Basil Achie
 
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779Delhi Call girls
 
SBFT Tool Competition 2024 - CPS-UAV Test Case Generation Track
SBFT Tool Competition 2024 - CPS-UAV Test Case Generation TrackSBFT Tool Competition 2024 - CPS-UAV Test Case Generation Track
SBFT Tool Competition 2024 - CPS-UAV Test Case Generation TrackSebastiano Panichella
 
SBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation TrackSBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation TrackSebastiano Panichella
 
Philippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.pptPhilippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.pptssuser319dad
 

Recently uploaded (20)

Russian Call Girls in Kolkata Vaishnavi 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Vaishnavi 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Vaishnavi 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Vaishnavi 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Simulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with AerialistSimulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with Aerialist
 
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
 
Microsoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AIMicrosoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AI
 
LANDMARKS AND MONUMENTS IN NIGERIA.pptx
LANDMARKS  AND MONUMENTS IN NIGERIA.pptxLANDMARKS  AND MONUMENTS IN NIGERIA.pptx
LANDMARKS AND MONUMENTS IN NIGERIA.pptx
 
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
 
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
 
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
 
George Lever - eCommerce Day Chile 2024
George Lever -  eCommerce Day Chile 2024George Lever -  eCommerce Day Chile 2024
George Lever - eCommerce Day Chile 2024
 
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfOpen Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
 
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfCTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
 
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
 
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
 
Motivation and Theory Maslow and Murray pdf
Motivation and Theory Maslow and Murray pdfMotivation and Theory Maslow and Murray pdf
Motivation and Theory Maslow and Murray pdf
 
The 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringThe 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software Engineering
 
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
 
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
 
SBFT Tool Competition 2024 - CPS-UAV Test Case Generation Track
SBFT Tool Competition 2024 - CPS-UAV Test Case Generation TrackSBFT Tool Competition 2024 - CPS-UAV Test Case Generation Track
SBFT Tool Competition 2024 - CPS-UAV Test Case Generation Track
 
SBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation TrackSBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation Track
 
Philippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.pptPhilippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.ppt
 

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(); }