C# GridView 在按钮单击更新数据时刷新

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1775791/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 20:42:50  来源:igfitidea点击:

GridView to refresh when button click updates data

c#asp.netdata-binding

提问by Degan

I have a button click event on a page which ultimate updates a table using:

我在页面上有一个按钮单击事件,它最终使用以下方法更新表:

protected void Button2_Click(object sender, EventArgs e)
{
    this.AccessDataSource6.Insert();
}

A GridView bound to a different AccessDataSource, displays data that is updated by the Insert.

绑定到不同 AccessDataSource 的 GridView 显示由 Insert 更新的数据。

What do I need to include in Button2_Click for the GridView to be refreshed?

我需要在 Button2_Click 中包含什么才能刷新 GridView?

采纳答案by JohnIdol

The GridView.DataBindMethod will clear and re-populate your grid view (assuming the datasource is already set - see the link for an example).

GridView.DataBind方法将清除并重新填充您的网格视图(假定数据源已经被设置-见链接的例子)。

回答by JohnIdol

On your click event after you insert you should called the GridView.DataBind() method to rebind the data...

在插入后的单击事件中,您应该调用 GridView.DataBind() 方法来重新绑定数据...

protected void Button2_Click(object sender, EventArgs e)
{
    this.AccessDataSource6.Insert();
    this.gridView1.DataBind();
}