Insert,Update and delete in listview using Xml file as datasource

XMl :

 
<?
xml version="1.0" encoding="utf-8"?>
<
NewElement>
<
Employee>
<
ID>1</ID>
<
Name>siva</Name>
</
Employee>
<
Employee>
<
ID>2</ID>
<
Name>abc</Name>
</
Employee>
<
Employee>
<
ID>3</ID>
<
Name>xyz</Name>
</
Employee>
<
Employee>
<
ID>4</ID>
<
Name>efg</Name>
</
Employee>
</
NewElement>



 .aspx:

<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head runat="server">
<title></title>
</
head>
<
body>
<form id="form1" runat="server">
<div>
<asp:ListView ID="lvEmployee" runat="server" InsertItemPosition="LastItem" OnItemInserting="lvEmployee_ItemInserting"
OnItemDeleting="lvEmployee_ItemDeleting" OnItemEditing="lvEmployee_ItemEditing"
OnItemCanceling="lvEmployee_ItemCanceling" >
<LayoutTemplate>
<table id="Table1" runat="server">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr id="Tr2" runat="server" style="">
<th id="Th1" runat="server">
</th>
<th id="Th2" runat="server">
ID
</th>
<th id="Th3" runat="server">
Name
</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr id="Tr3" runat="server">
<td id="Td2" runat="server" style="">
</td>
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr style="">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="lblID" runat="server" Text='<%# Bind("ID") %>' />
</td>
<td>
<asp:Label ID="lblName" runat="server" Text='<%# Bind("Name") %>' />
</td>
</tr>
</ItemTemplate>
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
</td>
<td>
&nbsp;
</td>
<td>
<asp:TextBox ID="txtID" runat="server" Text='<%# Bind("ID") %>' />
</td>
<td>
<asp:TextBox ID="txtName" runat="server" Text='<%# Bind("Name") %>' />
</td>
<td>
<asp:Button ID="btnUpdate" runat="server" Text="Update" OnClick="btnUpdate_Click" />
</td>
</tr>
</InsertItemTemplate>
</asp:ListView>
</div>
</form>
</
body>
</
html>




Ebook Download
View all
Learn
View all