我用gridview管理数据 我想做删除数据的同时把这个文件给删除掉,然后重新删除后的数据生成一个XML文件。
我在gridview的RowDeleteing中写了这样的代码 
  protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string strFilePath = e.Values["MPlaypath"].ToString();
        if (File.Exists(strFilePath))
        {
            File.Delete(strFilePath);
            xml();
        }    } public void xml()
    {
        DataSet ds = new DataSet();
        OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=D:\\Visual Studio 2008\\WebSites\\4-13\\App_Data\\media.mdb");
        OleDbCommand cmd = new OleDbCommand("select MName,MUppath,MPlaypath,MImgpath from Media", conn);
        OleDbDataAdapter oda = new OleDbDataAdapter(cmd);
        oda.Fill(ds);
        cmd.Dispose();
        conn.Close();
        ds.DataSetName = "root";
        ds.Tables[0].TableName = "Stream";
        ds.WriteXml(Server.MapPath("xml/news_list.xml"));
    }结果的话...点击gridview的删除好像只成功过一次把文件也删除掉的,生成新的数据的XML文件这个功能是完全没成功过 请问我应该怎么修改才能实现我想要的功能呢

解决方案 »

  1.   

     protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string strFilePath = e.Values["MPlaypath"].ToString();
            if (File.Exists(strFilePath))  
            {
                File.Delete(strFilePath);  //你这个文件删除掉了,后面又不创建这个文件,所以下次执行这个事件时,这个if条件永远不会成立,因为文件不存在。所以xml()只是第一次会执行,以后都进不来
                xml();
            }    }
      

  2.   


    2345678910   protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)     {         string strFilePath = e.Values["MPlaypath"].ToString();         if (File.Exists(strFilePath))         {      xml(); File.Delete(strFilePath);        }       }