从文本框插入数据后,将显示要添加的新行,但会显示旧数据。仅在刷新后才显示新行 [英] After Inserting data from textboxes , New row supposted to be shown but old data is shown on. Only after refresh the new row is shown
问题描述
简单问题。
我无法分享代码。这样做时AMATEUR会遇到什么问题。
我在加载时显示网格视图。
同时在按钮(插入)上显示gridview。
在加载事件中:
如果 不 IsPostBack 那么
db.ds = db.DisplayEmp()
GridView1.DataSource = db.ds
GridView1.DataBind()
结束 如果
谢谢大家
根据你的问题,你是在数据库中插入数据,但它不是将立即显示在您的网格上,但您可以在刷新页面后看到您的数据..
因此在按钮(插入)中存在刷新数据的问题。 ..你可以使用这样的东西...
1)创建一种方法来绑定你的网格...... >
受保护 Sub BindGrid()
' 获取来自数据库的数据并填充数据表或数据集
' 将数据绑定到网格
db.ds = db.DisplayEmp()
GridView1.DataSource = db.ds
GridView1.DataBind()
结束 Sub
2)打电话给这个功能页面加载以及在按钮(插入)结束时将数据插入数据库后点击这样...
受保护的 Sub Page_Load( ByVal sender 作为 对象, ByVal e As System.EventArgs)句柄 我 .Load
如果 不 IsPostBack 然后
BindGrid()
结束 如果
结束 Sub
就像这样...
受保护的 Sub btnInsert_Click( ByVal sender 作为 对象, ByVal e As System.EventArgs)句柄 btnInsert.Click
' < span class =code-comment>您的代码是为您的数据库添加新行
' 完成所有内容填充后插入数据调用函数
BindGrid()
结束 Sub
以这种方式更改代码并检查其工作与否...
如果您使用的是更新面板,那么您还需要更新它...
UpdatePanel1.Update()
Simple problem.
I cant share the code. What would be the usual problem an AMATEUR would do while doing this.
I am displaying grid view on load.
Displaying gridview also on Button(Insert) click.
And in load event:
If Not IsPostBack Then
db.ds = db.DisplayEmp()
GridView1.DataSource = db.ds
GridView1.DataBind()
End If
Thank u guys
as per your question, you are inserting data to your database but it's not going to display on your grid immediately, but you can see your data after page is refreshed..
so there is issue in Button(Insert) to refresh the data... you can use something like this...
1) create one method to bind your grid like this...
Protected Sub BindGrid() ' Get data from your database and fill your data table or dataset ' bind that data to your grid db.ds = db.DisplayEmp() GridView1.DataSource = db.ds GridView1.DataBind() End Sub
2) Call this funcation on Page Load as well as After inserting data to your database at the end of your Button(Insert) click like this...
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then BindGrid() End If End Sub
And like this...
Protected Sub btnInsert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnInsert.Click 'Your code to isnert new row to your database ' after all the stuff finish to insert data call your Function BindGrid() End Sub
make changes to your code in this manner and check out its working or not...
also if you are using Update Panel, then you need to update it also like this...
UpdatePanel1.Update()
这篇关于从文本框插入数据后,将显示要添加的新行,但会显示旧数据。仅在刷新后才显示新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!