XML格式:
<parameter Name="材料类别" FieldName="material_class" Width="100" if_display="1" Sort="1" Desc="在用" />
<parameter Name="材料名称" FieldName="material_name" Width="80" if_display="1" Sort="2" Desc="在用" />前台:有个gridview 绑定XML里面的数据。
<asp:TemplateField HeaderText="字段代号" SortExpression="field_code">
     <ItemTemplate>
         <asp:Label runat="server" ID="lab_code" Text='<%#DataBinder.Eval(Container, "DataItem.FieldName")%>'></asp:Label>                                       
     </ItemTemplate>
</asp:TemplateField>后台:
      for (int i = 0; i < gvQuery_Filed.Rows.Count; i++)
        {
            Label lab_field_code = gvQuery_Filed.Rows[i].FindControl("lab_code") as Label;//得到当前行的code
            TextBox txt_field_name = gvQuery_Filed.Rows[i].FindControl("txtGField_Name") as TextBox;
            CheckBox chk_if_display = gvQuery_Filed.Rows[i].FindControl("chkGIf_Display") as CheckBox;
            TextBox txt_format = gvQuery_Filed.Rows[i].FindControl("txtWidth") as TextBox;
            string str_field_code = lab_field_code.Text;
            string str_field_name = txt_field_name.Text;
            bool bl_if_dispaly = chk_if_display.Checked;
            string str_format = txt_format.Text;
            foreach (XmlNode xd in xWitsTablesList)
            {
                foreach (XmlNode xd2 in xd.ChildNodes)
                {
                    XmlElement xe = (XmlElement)xd2;//对XD进行类型转化
                    if (IsXMLUtility.XmlHelper.GetAttributeInnerText(xd2.Attributes["FieldName"]) == str_field_code)
                    {
                        
                        xe.SetAttribute("Name", str_field_name);//更新Name字段的值
                        if (bl_if_dispaly)
                        {
                            xe.SetAttribute("if_display", "1");
                        }
                        xe.SetAttribute("Width", str_format);
                        break;
                    }
                }
            }
            
           
        }思路是这样的:通过遍历gridview的行,获取当前行的code,然后查找xml里面的 FieldName字段等于code的一行,然后更新相对应的Width,if_display,Name属性的值。
我确定程序流程都走一遍,逻辑没问题,可是XML值就是不更新。

解决方案 »

  1.   

    xml文件有缓存,你每次操作需要先保存成物理文件,然后清空缓存重新绑定
      

  2.   

    你的操作应该只更新了内存中的xml
      

  3.   

    xe.SetAttribute("Name", str_field_name);//更新Name字段的值
       if (bl_if_dispaly)
       {
       xe.SetAttribute("if_display", "1");
       }
       xe.SetAttribute("Width", str_format);
       break; 加上:XmlDocument.Save(path);
      

  4.   

    XmlDocument xmlDoc = new XmlDocument();
            string fileName = (AppGlobal.AppControl.GetPhysicalApplicationPath() + "Xml\\GV_Xml\\" + "耗材销毁" + ".xml").Replace("WebSite", "WebService");//得到XML路径
            xmlDoc.Load(fileName);我的是这样的 你的参数path是我的fileName吗?
      

  5.   

    OK 谢谢,我解决了,问题出在我虽然操作了XML文件,但是没有保存,感谢nevermore_0923
    对我的帮助