XML文件(XMLFile):
<Stus>
<Stu>
<SID>1</SID>
<SName>野原美伢</SName>
<SSex>女</SSex>
<SAge>29</SAge>
</Stu>
<Stu>
<SID>2</SID>
<SName>野原新之助</SName>
<SSex>男</SSex>
<SAge>5</SAge>
</Stu>
<Stu>
<SID>3</SID>
<SName>野原葵</SName>
<SSex>女</SSex>
<SAge>2</SAge>
</Stu>
<Stu>
<SID>4</SID>
<SName>野原广</SName>
<SSex>男</SSex>
<SAge>34</SAge>
</Stu>
<Stu>
<SID>5</SID>
<SName>小白</SName>
<SSex>男</SSex>
<SAge>3</SAge>
</Stu>
</Stus>
aspx文件:
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("XMLFile.xml"));//读并绑定XML文件到ds
DataTable dt=ds.Tables[0];
for (int i = 0; i < dt.Rows.Count; i++)
{
if (ds.Tables[0].Rows[i]["SName"].ToString().Equals("野原A"))
{
ds.Tables[0].Rows[i]["SName"] = "野原广志";
}
}
ds.WriteXml(Server.MapPath("XMLFile.xml"));//写入修改到XML文件
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();//绑定并显示