C# 如何使用gridview从asp.net中的xml文件中删除和更新记录
我想通过选择gridview的行来更新和删除记录。此代码用于添加员工详细信息C# 如何使用gridview从asp.net中的xml文件中删除和更新记录,c#,asp.net,xml,C#,Asp.net,Xml,我想通过选择gridview的行来更新和删除记录。此代码用于添加员工详细信息 protected void Button_Add_Employee_Click(object sender, EventArgs e) { XmlDocument xmlEmloyeeDoc = new XmlDocument(); xmlEmloyeeDoc.Load(Server.MapPath("~/Employees.xml"));
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();
}``
只需编写这样的代码
更新:
受保护的无效GridView\u rowUpdateingObject发送方,GridViewUpdateEventTargets e
{
数据集ds=新数据集;
ds.ReadXmlServer.MapPath~/YourXmlFilePath;
int iXmlRow=Convert.ToInt32Convert.ToStringViewState[gridrow];
表[0]。行[iXmlRow][Name]=txtFirstName.Text;
ds.Tables[0]。行[iXmlRow][Designation]=txtLastName.Text;
.....
等
ds.WriteXmlServer.MapPath~/YourXMLPath;
BindGrid;
}
删除:
受保护的无效GridView\u行删除对象发送方,GridViewDeleteEventArgs e
{
数据集ds=新数据集;
ds.ReadXmlServer.MapPath~/YourXmlFilePath;
ds.Tables[0].Rows.RemoveAte.RowIndex;
ds.WriteXmlServer.MapPath~/YourXmlFilePath;
BindGrid;
}
希望这有助于`