2016-08-03 3 views
-2

グリッドビューの行を選択してレコードを更新および削除したいとします。このコードは従業員の詳細を追加するためのコードです。更新するためasp.netのxmlファイルからgridviewを使用してレコードを削除および更新する方法

protected void Button_Add_Employee_Click(object sender, EventArgs e) 
     { 
      XmlDocument xmlEmloyeeDoc = new XmlDocument(); 
      xmlEmloyeeDoc.Load(Server.MapPath("~/Employees.xml")); 
      XmlElement ParentElement = xmlEmloyeeDoc.CreateElement("Employee"); 
      XmlElement ID = xmlEmloyeeDoc.CreateElement("ID"); 
      ID.InnerText = TextBox_Id.Text; 
      XmlElement Name = xmlEmloyeeDoc.CreateElement("Name"); 
      Name.InnerText = TextBox_Name.Text; 
      XmlElement Designation = xmlEmloyeeDoc.CreateElement("Designation"); 
      Designation.InnerText = TextBox_Desig.Text; 

      ParentElement.AppendChild(ID); 
      ParentElement.AppendChild(Name); 
      ParentElement.AppendChild(Designation); 

      xmlEmloyeeDoc.DocumentElement.AppendChild(ParentElement); 
      xmlEmloyeeDoc.Save(Server.MapPath("~/Employees.xml")); 
      BindGrid();   
     }`` 

答えて

0

Just write code like this 保護ボイドGridView_RowUpdating(オブジェクト送信者、GridViewUpdateEventArgs E) { データセットDS =新しいデータセットを()。 ds.ReadXml(Server.MapPath( "〜/ YourXmlFilePath")); int iXmlRow = Convert.ToInt32(Convert.ToString(ViewState ["gridrow"])); ds.Tables [0] .Rows [iXmlRow] ["Name"] = txtFirstName.Text; ds.Tables [0] .Rows [iXmlRow] ["指定"] = txtLastName.Text; ..... など ds.WriteXml(Server.MapPath( "〜/ YourXMLPath")); BindGrid(); }削除する 保護ボイドGridView_RowDeleting(オブジェクト送信者、GridViewDeleteEventArgs E) { データセットDS =新しいデータセット()。 ds.ReadXml(Server.MapPath( "〜/ YourXmlFilePath")); ds.Tables [0] .Rows.RemoveAt(e.RowIndex); ds.WriteXml(Server.MapPath( "〜/ YourXmlFilePath")); BindGrid(); } 希望のヘルプ... '

関連する問題