使用XML读写删除功能来实现资源文件配置

资源文件的配置,暂不支持编辑,如果要编辑直接删除后新增就可以了。
使用XML读写删除功能来实现资源文件配置
1.添加资源文件strings.zh-cn.resx和strings.en-us.resx
也可以参考 资源文件配置和使用
<? xml version="1.0" encoding="utf-8" ?>
< root >
  
< xsd:schema  id ="root"  xmlns =""  xmlns:xsd ="http://www.w3.org/2001/XMLSchema"  xmlns:msdata ="urn:schemas-microsoft-com:xml-msdata" >
    
< xsd:element  name ="root"  msdata:IsDataSet ="true" >
      
< xsd:complexType >
        
< xsd:choice  maxOccurs ="unbounded" >
          
< xsd:element  name ="data" >
            
< xsd:complexType >
              
< xsd:sequence >
                
< xsd:element  name ="value"  type ="xsd:string"  minOccurs ="0"  msdata:Ordinal ="1"   />
                
< xsd:element  name ="comment"  type ="xsd:string"  minOccurs ="0"  msdata:Ordinal ="2"   />
              
</ xsd:sequence >
              
< xsd:attribute  name ="name"  type ="xsd:string"   />
              
< xsd:attribute  name ="type"  type ="xsd:string"   />
              
< xsd:attribute  name ="mimetype"  type ="xsd:string"   />
            
</ xsd:complexType >
          
</ xsd:element >
          
< xsd:element  name ="resheader" >
            
< xsd:complexType >
              
< xsd:sequence >
                
< xsd:element  name ="value"  type ="xsd:string"  minOccurs ="0"  msdata:Ordinal ="1"   />
              
</ xsd:sequence >
              
< xsd:attribute  name ="name"  type ="xsd:string"  use ="required"   />
            
</ xsd:complexType >
          
</ xsd:element >
        
</ xsd:choice >
      
</ xsd:complexType >
    
</ xsd:element >
  
</ xsd:schema >
  
< resheader  name ="ResMimeType" >
    
< value > text/microsoft-resx </ value >
  
</ resheader >
  
< resheader  name ="Version" >
    
< value > 1.0.0.0 </ value >
  
</ resheader >
  
< resheader  name ="Reader" >
    
< value > System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 </ value >
  
</ resheader >
  
< resheader  name ="Writer" >
    
< value > System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 </ value >
  
</ resheader >
  
< data  name ="LoginName" >
    
< value > 用户名 </ value >
  
</ data >
  
< data  name ="Password" >
    
< value > 密码 </ value >
  
</ data >   
</ root >
2.html代码
< HTML >
    
< HEAD >
        
< title > XMLGrid </ title >
        
< meta  content ="Microsoft Visual Studio .NET 7.1"  name ="GENERATOR" >
        
< meta  content ="C#"  name ="CODE_LANGUAGE" >
        
< meta  content ="JavaScript"  name ="vs_defaultClientScript" >
        
< meta  content ="http://schemas.microsoft.com/intellisense/ie5"  name ="vs_targetSchema" >
        
< script  language =javascript >
            
function test(obj)
            
{
                
var id = obj.id;
                
var objs;
                
if(id!="")
                
{
                    
var len = id.length;
                    
var objs = obj.children;
                }
                
                document.getElementById(
"<%=TextBox1.ClientID%>").innerText=objs[1].innerText;
                document.getElementById(
"<%=TextBox2.ClientID%>").innerText=objs[2].innerText;
            }

        
</ script >
    
</ HEAD >
    
< body  MS_POSITIONING ="GridLayout" >
        
< form  id ="Form1"  method ="post"  runat ="server" >
            
< TABLE  id ="Table1"  style ="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px"  cellSpacing ="1"
                cellPadding
="1"  width ="300"  border ="1" >
                
< tr >
                    
< td  colspan ="2" > 资源文件配置 </ td >
                
</ tr >
                
< tr >
                    
< td > Language </ td >
                    
< td >< asp:dropdownlist  id ="DropDownList1"  runat ="server"  AutoPostBack ="True" >
                            
< asp:ListItem  Value ="zh-cn" > 中文 </ asp:ListItem >
                            
< asp:ListItem  Value ="en-us" > 英文 </ asp:ListItem >
                        
</ asp:dropdownlist ></ td >
                
</ tr >
                
< TR >
                    
< TD > Name </ TD >
                    
< TD >< asp:textbox  id ="TextBox1"  runat ="server" ></ asp:textbox ></ TD >
                
</ TR >
                
< TR >
                    
< TD > Value </ TD >
                    
< TD >< asp:textbox  id ="TextBox2"  runat ="server" ></ asp:textbox ></ TD >
                
</ TR >
                
< TR >
                    
< TD ></ TD >
                    
< TD >< asp:button  id ="Button1"  runat ="server"  Text ="新增" ></ asp:button ></ TD >
                
</ TR >
            
</ TABLE >
            
< asp:datagrid  id ="DataGrid1"  style ="Z-INDEX: 102; LEFT: 8px; POSITION: absolute; TOP: 160px"  runat ="server"
                AutoGenerateColumns
="False"  DataKeyField ="name"  BorderColor ="#CC9966"  BorderWidth ="1px"  BackColor ="White"
                CellPadding
="4"  OnDeleteCommand ="Delete"  BorderStyle ="None" >
                
< FooterStyle  ForeColor ="#330099"  BackColor ="#FFFFCC" ></ FooterStyle >
                
< SelectedItemStyle  Font-Bold ="True"  ForeColor ="#663399"  BackColor ="#FFCC66" ></ SelectedItemStyle >
                
< ItemStyle  ForeColor ="#330099"  BackColor ="White" ></ ItemStyle >
                
< HeaderStyle  Font-Bold ="True"  ForeColor ="#FFFFCC"  BackColor ="#990000" ></ HeaderStyle >
                
< Columns >
                    
< asp:TemplateColumn  HeaderText ="序号" >
                        
< ItemTemplate >
                            
<% # Container.ItemIndex+1  %>
                        
</ ItemTemplate >
                    
</ asp:TemplateColumn >
                    
< asp:BoundColumn  DataField ="name"  ReadOnly ="True"  HeaderText ="Name" ></ asp:BoundColumn >
                    
< asp:TemplateColumn  HeaderText ="Value" >
                        
< ItemTemplate >
                            
<% # DataBinder.Eval(Container.DataItem,"value" %>
                        
</ ItemTemplate >
                        
< EditItemTemplate >
                            
< asp:TextBox  ID =txtvalue  Runat =server  Text ='<%#  DataBinder.Eval(Container.DataItem,"value") % > '>
                            
</ asp:TextBox >
                        
</ EditItemTemplate >
                    
</ asp:TemplateColumn >
                    
< asp:ButtonColumn  Text ="删除"  ButtonType ="PushButton"  HeaderText ="删除"  CommandName ="Delete" ></ asp:ButtonColumn >
                
</ Columns >
            
</ asp:datagrid >
        
</ form >
    
</ body >
</ HTML >
3. cs代码
public   class  WebForm1 : System.Web.UI.Page
    
{
        
private XmlNode node=null;
        
protected System.Web.UI.WebControls.DropDownList DropDownList1;
        
protected System.Web.UI.WebControls.TextBox TextBox1;
        
protected System.Web.UI.WebControls.TextBox TextBox2;
        
protected System.Web.UI.WebControls.Button Button1;
        
protected System.Web.UI.WebControls.DataGrid DataGrid1;
        
private void Page_Load(object sender, System.EventArgs e)
        
{
            
if(!Page.IsPostBack)
            
{    
                DataBind();
            }

        }


        
DataBind

        
SetValue

        
saveDoc

        
removeElement

        
Web Form Designer generated code

        
property

        
Button1_Click

        
Delete

        
AlertError

        
DropDownList1_SelectedIndexChanged

        
DataGrid1_ItemDataBound
    }

你可能感兴趣的:(xml)