ASP.Net 更新储存在xml文件中的数据(update操作)
XML文件请见ASP.Net中实现XMl的标识列(ID列)或自增长列
代码如下:
更新按钮事件:
Xml_UpDt方法:
OperateXmlByDataSet的UpdateXmlRow方法:
代码如下:
更新按钮事件:
private void Btn_update_Click(object sender, System.EventArgs e)
{
Xml_UpDt(ViewState["uid"].ToString());//调用Xml_UpDt方法
BindDG();//重新绑定datagrid
}
{
Xml_UpDt(ViewState["uid"].ToString());//调用Xml_UpDt方法
BindDG();//重新绑定datagrid
}
Xml_UpDt方法:
void Xml_UpDt(string userid)
{
string username = this.Txt_name.Text;
string userpass = this.Txt_pass.Text;
string usermail = this.Txt_mail.Text;
string usersite = this.Txt_site.Text;
string usermsn = this.Txt_msn.Text;
string [] Columns = {"username","userpass","usermail","usersite","usermsn"};
string [] ColumnsValues = {username,userpass,usermail,usersite,usermsn};
OperateXmlByDataSet.UpdateXmlRow(ViewState["filename"].ToString(),Columns,ColumnsValues,"userid",userid);
}
ViewState["filename"]= Server.MapPath("..//XML//User.xml");{
string username = this.Txt_name.Text;
string userpass = this.Txt_pass.Text;
string usermail = this.Txt_mail.Text;
string usersite = this.Txt_site.Text;
string usermsn = this.Txt_msn.Text;
string [] Columns = {"username","userpass","usermail","usersite","usermsn"};
string [] ColumnsValues = {username,userpass,usermail,usersite,usermsn};
OperateXmlByDataSet.UpdateXmlRow(ViewState["filename"].ToString(),Columns,ColumnsValues,"userid",userid);
}
OperateXmlByDataSet的UpdateXmlRow方法:
UpdateXmlRow
作者:青羽