我有同样的问题:
但是提供的答案对我不起作用,我在寻求想法,因为到目前为止,我已经浪费了 3 天时间试图让 GridView 在 DetailsView 的回发时刷新。
情况是这样的:-
I have a GridView that when a row is selected a DetailsView displays the detailed info. 在。
单击编辑时,DetailsView 进入“编辑”模式。
我编辑它并单击更新按钮。
更新会触发一个事件,它会正确更新我的 SQL 数据库表。
问题是尽管有 100 篇帖子说使用 GridView1.Databind(); 在我单击取消按钮之前它不会刷新。
我知道它的回发,因为我已经对其进行了调试并在 Page_load(...) 回发中看到了它。
我已经添加了
SqlDataSource1.DataBind();
和
GridView1.DataBind()
到以下地方,似乎都没有刷新我的 GridView。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
...
}
else
{
SqlDataSource1.DataBind();
GridView1.DataBind();
}
}
还
protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
{
GridView1.DataBind();
}
还
protected void DetailsView1_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
{
//GridView.SelectedIndex = -1;
SqlDataSource1.EnableCaching = false;
// UpdatePanel14.Update();
SqlDataSource1.DataBind();
GridView1.DataBind();
SqlDataSource1.EnableCaching = true;
// EndEditingGridView();
}
如您所见,我也尝试过在 Page_Load() 下进行回发,也包括在 DetailsView 的更新和更新中。我也尝试在 GridView 上设置“ViewState = Disabled”。除非我单击“取消”按钮,否则似乎没有任何东西可以更新其内容。谢谢。