using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using System.Xml;
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataSet mydsRead = new DataSet();
            mydsRead.ReadXml(Server.MapPath("XMLFile.xml"));
            GridView1.DataSource = mydsRead;
            GridView1.DataBind();
            DropDownList1.DataSource = mydsRead;
            DropDownList1.DataTextField = "仓库面积";
            DropDownList1.DataBind();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        XmlDocument doc = new XmlDocument();
        doc.Load(Server.MapPath("XMLFile.xml"));
        XmlNodeList xnl = doc.SelectSingleNode("dataroot").ChildNodes; ;//获取dataroot节点的所有子节点
        foreach (XmlNode xn in xnl)//遍历所有子节点
        {
            XmlElement xe = (XmlElement)xn;//将子节点类型转换为XmlElement类型
            if (xe.Name == "仓库")//判断节点名为仓库
            {
                XmlNodeList xnlChild = xe.ChildNodes;//继续获取xe子节点的所有子节点
                foreach (XmlNode xnChild in xnlChild)//遍历
                {
                    XmlElement xeChild = (XmlElement)xnChild;//转换类型
                    if (xeChild.Name == "仓库面积" && xeChild.InnerText == this.DropDownList1.SelectedValue.Trim())
                    {
                        xeChild.InnerText = TextBox1.Text.Trim();
                        Response.Write("<script>alert('修改节点数据成功!')</script>");
                        break;
                    }
                }
            }
        }
        doc.Save(Server.MapPath("XMLFile.xml"));
       Response.Write("<script>location='Default.aspx'</script>");
    }
}
