步步为营VS 2008 + .NET 3.5(14) - XLINQ(LINQ to XML)之针对XML文件的添加、查询、更新和删除
作者:webabcd
介绍
以某一XML文件为例,XLINQ(LINQ to XML)之针对XML文件的添加操作、查询操作、更新操作和删除操作
示例
Sample.xml
<?xml version="1.0" encoding="utf-8"?>
<root>
<person name="webabcd" age="27" salary="33" />
</root>
<root>
<person name="webabcd" age="27" salary="33" />
</root>
Sample.aspx
<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Sample.aspx.cs"
Inherits="LINQ_XLINQ_Sample" Title="针对XML文件的添加、查询、更新和删除" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<p>
姓名:<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
年龄:<asp:TextBox ID="txtAge" runat="server"></asp:TextBox>
薪水:<asp:TextBox ID="txtSalary" runat="server"></asp:TextBox>
<asp:Button ID="btnAdd" runat="server" Text="添加" OnClick="btnAdd_Click" />
</p>
<asp:GridView ID="gvPerson" runat="server" DataKeyNames="name" OnSelectedIndexChanged="gvPerson_SelectedIndexChanged"
OnRowDeleting="gvPerson_RowDeleting" OnRowCancelingEdit="gvPerson_RowCancelingEdit"
OnRowEditing="gvPerson_RowEditing" OnRowUpdating="gvPerson_RowUpdating">
<Columns>
<asp:CommandField ShowSelectButton="True" ShowEditButton="True" ShowDeleteButton="True">
</asp:CommandField>
</Columns>
</asp:GridView>
<br />
<asp:DetailsView ID="dvPerson" runat="server" DataKeyNames="name">
</asp:DetailsView>
</asp:Content>
Inherits="LINQ_XLINQ_Sample" Title="针对XML文件的添加、查询、更新和删除" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<p>
姓名:<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
年龄:<asp:TextBox ID="txtAge" runat="server"></asp:TextBox>
薪水:<asp:TextBox ID="txtSalary" runat="server"></asp:TextBox>
<asp:Button ID="btnAdd" runat="server" Text="添加" OnClick="btnAdd_Click" />
</p>
<asp:GridView ID="gvPerson" runat="server" DataKeyNames="name" OnSelectedIndexChanged="gvPerson_SelectedIndexChanged"
OnRowDeleting="gvPerson_RowDeleting" OnRowCancelingEdit="gvPerson_RowCancelingEdit"
OnRowEditing="gvPerson_RowEditing" OnRowUpdating="gvPerson_RowUpdating">
<Columns>
<asp:CommandField ShowSelectButton="True" ShowEditButton="True" ShowDeleteButton="True">
</asp:CommandField>
</Columns>
</asp:GridView>
<br />
<asp:DetailsView ID="dvPerson" runat="server" DataKeyNames="name">
</asp:DetailsView>
</asp:Content>
Sample.aspx.cs










































































































































OK
[源码下载]
本文出自 “webabcd” 博客,请务必保留此出处http://webabcd.blog.51cto.com/1787395/345020