asp.net gridview的代码隐藏更新

时间:2013-04-23 20:28:50

标签: asp.net sql gridview

我有一个GridView,它由代码隐藏代码更新,通过在TextBox中输入文本并为按钮计时来更新SQL源代码。我一直在搜索更新SQL源后如何更新GridView,我没有找到答案。按钮单击和SQL源更改的代码是:

protected void btnSubmit_Click(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
         sqlSource.InsertParameters["x"].DefaultValue = User.Identity.Name.ToString();
         sqlSource.InsertParameters["y"].DefaultValue = ((TextBox)this.FindControl("abc")).Text;
         sqlSource.InsertParameters["z"].DefaultValue = DateTime.Now.ToString();
         sqlSource.Insert(); 
    }
}

我应该为此功能添加什么,以便在按下按钮时更新GridView?

1 个答案:

答案 0 :(得分:2)

按钮点击ASP.NET需要始终回发。你像编写页面加载事件一样编写代码。

并从代码写入绑定gridview。

gridview1.datasource = sqlSource;
gridview1.Databind();

相关问题