保存记录后如何刷新页面并在gridview中查看该记录? [英] After saving a record in how to refresh the page and see that record in gridview?

查看:48
本文介绍了保存记录后如何刷新页面并在gridview中查看该记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SqlCommand cmd = new SqlCommand("exec insertDepartement @DepartmentName", con);
cmd.Parameters.AddWithValue("@DepartmentName", TextBox1.Text);
con.Close();
con.Open();
cmd.ExecuteNonQuery();

Page_Load(sender, e);

推荐答案



执行insert语句后,调用函数以获取数据集并将其绑定到gridview.

希望这对您有帮助.


After you execute the insert statement.Call the function to get the dataset and bind it to the gridview.

Hope this helps.


您好.无需刷新整个页面即可显示最后插入的记录...?请按照以下步骤操作:

首先将ajax更新面板用于gridview

接下来,在cmd.executenonquery()之后调用网格绑定方法.请参见下面的示例

Hi..No need to refresh the whole page to display last inserted record...?Follow these steps :

First use the ajax update panel for gridview

Next,call the grid binded method after the cmd.executenonquery()..see the example below

SqlCommand cmd = new SqlCommand("exec insertDepartement @DepartmentName", con);
            cmd.Parameters.AddWithValue("@DepartmentName", TextBox1.Text);            
            con.Close();
            con.Open();
            cmd.ExecuteNonQuery();
            bindgrid();



创建一个名为bindgrid()
的方法



create a method called bindgrid()

public void bindgrid()
{
  sqlcommand com=new sqlcommand("select * from table");
sqladapter da=new sqladapter(com,con);
da.Fill(ds)
    gridview1.datasource=ds;
    gridview1.databind();
}


这篇关于保存记录后如何刷新页面并在gridview中查看该记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆