学习疑惑:在Updatepanel控件中放置了Gridview控件和触发更新的button控件,Gridview控件已经绑定到数据库,输入数据到数据库后,想让Gridview控件即时刷新显示。但是实际是毫无反应。关闭页面后再次打开才能刷新出来。
解决办法:即使已经将Gridview控件绑定到数据库,每次使用button控件触发更新时仍要再次绑定Gridview控件。而且这个问题与Gridview控件的cacheEnable属性没有关系。
相关代码:
cs文件:
protected void Button1_Click(object sender, EventArgs e)
{
string msg = this.TextBox1.Text;
int affectRow=0;
string str = "server=.;database=db_Ajax;uid=sa;pwd=123456;";
SqlConnection con = new SqlConnection(str);
SqlCommand cmd = new SqlCommand("insert into tb_user(id,ip) values(3,'3.3.3.3')", con);
try
{
con.Open();
affectRow=cmd.ExecuteNonQuery();
}
catch(SqlException Exception)