<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="XMLLeaveWordBorad.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>
<style type="text/css">
.table
{
font-size: 10pt;
color: #666666;
}
</style>
</head>
<body style=" margin-top:0px;">
<form ></asp:Label>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
-------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Data;
namespace XMLLeaveWordBorad
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("Content.xml"));
XmlNode xnode = doc.SelectSingleNode("content");
XmlElement el = doc.CreateElement("person");
XmlAttribute attrName = doc.CreateAttribute("name");
attrName.Value = txtName.Text;
el.Attributes.Append(attrName);
XmlAttribute attrQQ = doc.CreateAttribute("qq");
attrQQ.Value = txtQQ.Text;
el.Attributes.Append(attrQQ);
XmlAttribute attrEmail = doc.CreateAttribute("email");
attrEmail.Value = txtEmail.Text;
el.Attributes.Append(attrEmail);
XmlAttribute attrTel = doc.CreateAttribute("tel");
attrTel.Value = txtTel.Text;
el.Attributes.Append(attrTel);
el.InnerText = txtCotent.Text;
xnode.AppendChild(el);
doc.Save(Server.MapPath("Content.xml"));
BindGrid();
}
public void BindGrid()
{
DataSet store = new DataSet();
store.ReadXml(Server.MapPath("Content.xml"));
gridContent.DataSource = store;
gridContent.DataBind();
}
protected void btnSelect_Click(object sender, EventArgs e)
{
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("Content.xml"));
XmlNode xnode = doc.SelectSingleNode("content");
XmlNodeList list = doc.SelectSingleNode("content").ChildNodes;
foreach(XmlNode node in list)
{
if (node.Attributes["name"].Value == txtSelect.Text)
{
lblPerson.Text = node.Attributes["name"].Value;
lblQQ.Text = node.Attributes["qq"].Value;
lblEmail.Text = node.Attributes["email"].Value;
lblTel.Text = node.Attributes["tel"].Value;
lblContent.Text = node.InnerText;
}
}
}
}
}