一个修改XML的里字段值的代码

        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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值