GridView中显示了已删除的DATAS [英] Gridview showing up deleted datas
问题描述
我只显示我的GridView我上传文件的详细信息,因此将只有一个在我的GridView行 - 多个文件是不允许的。
当我删除该单列,并尝试上传一个新的文件,它显示2行(新文件和删除的文件)。
我已经尝试过使用 GridView.DataSource = NULL
和 GridView.DataBind()
。
注:我rebinded我的GridView中删除后,但它仍然显示了删除文件
保护无效DeleteLinkButton_Click(对象发件人,EventArgs的发送)
{
如果(会话[名称]!= NULL)
{
串strPath的=会话[文件路径]的ToString()。
System.IO.File.Delete(strPath的); GridView2.Rows [0] =。可见假的;
Label8.Text =;
会话[文件名] = NULL;
Button3.Enabled = TRUE;
} GridView2.DataBind();
}
在某些情况下,我不得不做这样的事情:
//页面级变量
布尔refreshRequired = FALSE;保护无效DeleteLinkButton_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屋!