GridView中显示了已删除的DATAS [英] Gridview showing up deleted datas

查看:80
本文介绍了GridView中显示了已删除的DATAS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只显示我的GridView我上传文件的详细信息,因此将只有一个在我的GridView行 - 多个文件是不允许的。

当我删除该单列,并尝试上传一个新的文件,它显示2行(新文件​​和删除的文件)。

我已经尝试过使用 GridView.DataSource = NULL GridView.DataBind()

注:我rebinded我的GridView中删除后,但它仍然显示了删除文件

 保护无效DeleteLinkBut​​ton_Click(对象发件人,EventArgs的发送)
{
    如果(会话[名称]!= NULL)
    {
        串strPath的=会话[文件路径]的ToString()。
        System.IO.File.Delete(strPath的);        GridView2.Rows [0] =。可见假的;
        Label8.Text =;
        会话[文件名] = NULL;
        Button3.Enabled = TRUE;
    }    GridView2.DataBind();
}


解决方案

在某些情况下,我不得不做这样的事情:

  //页面级变量
布尔refreshRequired = FALSE;保护无效DeleteLinkBut​​ton_Click(对象发件人,EventArgs的发送)
{
    如果(会话[名称]!= NULL)
    {
        串strPath的=会话[文件路径]的ToString()。
        System.IO.File.Delete(strPath的);        GridView2.Rows [0] =。可见假的;
        Label8.Text =;
        会话[文件名] = NULL;
        Button3.Enabled = TRUE;        refreshRequired = TRUE;
    }}保护无效Page_ preRender(对象发件人,EventArgs的发送)
{
    如果(refreshRequired)
    {
        //无论你设置你的网格数据集,在这里做
        //但一定要获得新数据
    }
}

时间删除,网格绑定到旧数据。当您更改的数据,必须将它重新绑定到新的。

I just display my uploaded file details in my GridView, so there will be only one row in my GridView - multiple files are not allowed.

When I delete that single row and try to upload a new file, it is showing 2 rows (the new file and the deleted file).

I already tried using GridView.DataSource = null and GridView.DataBind().

Note: I've rebinded my GridView after the delete, but it still shows the deleted file.

protected void DeleteLinkButton_Click(object sender, EventArgs e)
{
    if (Session["name"] != null)
    {
        string strPath = Session["filepath"].ToString();
        System.IO.File.Delete(strPath);

        GridView2.Rows[0].Visible = false;
        Label8.Text = "";
        Session["filename"] = null;
        Button3.Enabled = true;
    }

    GridView2.DataBind();
}

解决方案

In some cases I've had to do something like this:

//page level variable
bool refreshRequired = false;

protected void DeleteLinkButton_Click(object sender, EventArgs e)
{
    if (Session["name"] != null)
    {
        string strPath = Session["filepath"].ToString();
        System.IO.File.Delete(strPath);

        GridView2.Rows[0].Visible = false;
        Label8.Text = "";
        Session["filename"] = null;
        Button3.Enabled = true;

        refreshRequired = true;
    }

}

protected void Page_PreRender(object sender, EventArgs e)
{
    if(refreshRequired)
    {
        //whatever you to to set your grids dataset, do it here
        //but be sure to get the NEW data
    }
}

At the time of Delete, your grid is bound to the old data. When you change the data, you must rebind it to the new.

这篇关于GridView中显示了已删除的DATAS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆