绑定网格中的问题 [英] problem in binding grid

查看:71
本文介绍了绑定网格中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hai专家,



我正在做一个Windows应用程序。

我有一个表单,可以在单击保存按钮时添加用户详细信息用户详细信息将添加到database.I有一个datagridview以另一种形式绑定用户详细信息,由第一个表单添加。但我的绑定不能正常工作



问题是当我点击保存按钮时网格没有绑定。但是如果我关闭应用程序并打开它,网格将绑定



我的代码绑定网格



public void BindEmployeeGrid()

{



DataTable dt = dalObj .GetUserDetails();

gvUserDetails.AutoGenerateColumns = false;

gvUserDetails.DataSource = dt;

}

hai experts,

I am doing a windows application.
I have a form to add user details on clicking the save button the user details will be added to database.I have a datagridview in another form to bind the user details which is added by the first form.But my binding is not working properly

The problem is when i click save button the grid is not binding.But if i Close the application and open it the grid will bind

my code to bind grid

public void BindEmployeeGrid()
{

DataTable dt = dalObj.GetUserDetails();
gvUserDetails.AutoGenerateColumns = false;
gvUserDetails.DataSource = dt;
}

推荐答案

1.问题是你的数据对象正在乞讨加载数据,而不是缓存数据,网格将与这个缓存的d绑定ATA。



2.因此,当用户添加/修改/删除数据时,您必须刷新数据对象以从数据库重新加载数据,然后网格将显示更新的数据。
1.The problem is that your "data object" is loading the data at the begging, than will cache the data and the grid will be bind with this cached data.

2.So when the user will add/modify/delete data you have to refresh your "data object" to reload the data from the database, then the grid will show the updated data.


您好,请试试这个:



请使用gvUserDetails.DataBind();最后。



public void BindEmployeeGrid()

{



DataTable dt = dalObj.GetUserDetails();

gvUserDetails.AutoGenerateColumns = false;

gvUserDetails.DataSource = dt;

gvUserDetails.DataBind() ;

}



希望这能解决您的问题。
Hi, please try this:

Please use gvUserDetails.DataBind(); at the end.

public void BindEmployeeGrid()
{

DataTable dt = dalObj.GetUserDetails();
gvUserDetails.AutoGenerateColumns = false;
gvUserDetails.DataSource = dt;
gvUserDetails.DataBind();
}

Hope this will solve your problem.


这篇关于绑定网格中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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