string xmlfile = "~/app_data/code.xml";
DataSet ds = new DataSet();//创建一个DataSet并建一个表
ds.ReadXml(Server.MapPath(xmlfile));//读取XML文件
//设置主键
ds.Tables[0].PrimaryKey = new DataColumn[] { ds.Tables[0].Columns["xian_code"] };
//在名为ds的DataSet中找到第一个表,再找到这个表的主键列为xian_code的行,设置这行的列名为db这个值为
GridViewRow row = this.GV_dblink.Rows[e.RowIndex];//
TextBox tb = (TextBox)row.Cells[4].FindControl("TB_DB");//获得控件里的控件
string db = tb.Text.ToString().Trim();//所修改的字段新值
string id = this.GV_dblink.Rows[e.RowIndex].Cells[3].Text.ToString().Trim();//所要修改的行
ds.Tables[0].Rows.Find(id)["db"] = Server.HtmlEncode(db);
ds.WriteXml(Server.MapPath("~/app_data/code.xml"));//将ds的更改写进xml中
this.GV_dblink.EditIndex = -1;//将GRIDVIEW退出编辑状态
this.filldbadv();//重新填充GRIDVIEW
一个修改XML的里字段值的代码
最新推荐文章于 2017-07-24 12:09:00 发布