main.aspx.cs页面
private void Page_Load(object sender, System.EventArgs e)
{
if(Request.QueryString["action"]=="drop")
{
string id = Request.QueryString["id"];
string file = Server.MapPath("upload/"+Request.QueryString["file"]);
fso.DropFile(file,Convert.ToInt16(id));
}
FillData();
this.myButton.Attributes.Add("onClick","return confirm('Are You Sure?');");
}
private void FillData()
{
this.Repeater1.DataSource=f.filelist();
this.Repeater1.DataBind();
}
fileList(int id)方法:
public DataTable getFileList()
{
this._sql = "select * from files order by id desc";
OleDbDataAdapter da = new OleDbDataAdapter(this._sql,this._ConnStr);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable t = ds.Tables[0];
return t;
}
点击了删除之后,也就是action="drop"了,文件删除了。但FillData();方法执行后绑定的数据还是删除前的数据,只有手工刷新本页以后才是新的数据,这是为什么?

解决方案 »

  1.   

    单步调试一下看看是否执行了FillData();
      

  2.   

    private void Page_Load(object sender, System.EventArgs e)
    {
    if(!Page.IsPostBack)
    {
    if(Request.QueryString["action"]=="drop")
    {
    string id = Request.QueryString["id"];
    string file = Server.MapPath("upload/"+Request.QueryString["file"]);
    fso.DropFile(file,Convert.ToInt16(id));
    }

    FillData(0);
    }
    this.myButton.Attributes.Add("onClick","return confirm('Are You Sure?');");
    }
    改成这样,还是一样。。
      

  3.   

    是啊,如果不加!isPostBack的话,每次都会调用fillData的,所以不会更新的。
      

  4.   

    page_load里面加if(!IsPostBack)
    然后是删除后加上DG.databind()
    其中DG是datagrid
      

  5.   

    Page_Load
    {
      if(!IsPostBack)
       {
          这里是你的代码
       }
    }
      

  6.   

    在删除后,要重新再对DataGrid进行绑定
    Page_Load里别忘了写上  if(!IsPostBack){}
      

  7.   

    fso.DropFile(file,Convert.ToInt16(id));后加上this.FillData();
      

  8.   

    private void Page_Load(object sender, System.EventArgs e)
    {
    if(!Page.IsPostBack)
    {
    if(Request.QueryString["action"]=="drop")
    {
    string id = Request.QueryString["id"];
    string file = Server.MapPath("upload/"+Request.QueryString["file"]);
    fso.DropFile(file,Convert.ToInt16(id));
    FillData(0);
    }
    FillData(0);
    }

    this.myButton.Attributes.Add("onClick","return confirm('Are You Sure?');");
    }
    还是不行...
      

  9.   

    page_load里面加if(!IsPostBack)
                      BindData();