在datagrid中显示数据时出现问题 [英] Problem in displaying data in datagrid

查看:128
本文介绍了在datagrid中显示数据时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我是玛尼.我在datagrid中显示数据时遇到问题.
我所做的是创建一个表单,并在此表单中创建了6个文本框和一个搜索按钮.每当用户在文本框中输入文本时,我都会根据用户输入并显示在datagrid中的文本从数据库中检索数据.
问题是,当用户再次在文本框中输入文本时,datagrid充满了新数据,而最后的数据将丢失.但是我希望新搜索的数据应显示在包括最后检索到的数据的datagrid中.

如果有人知道应该怎么做,请回复我.

问候,
manikanta.表到数据网格,

2)如果它是Web应用程序,则可以通过将数据表保留在会话变量中来执行相同的操作.


你好sekharkaza,
如果您不介意的话,可以举个例子来维护会话变量中的数据表.


Mani,


 session["Nameofyourchoice"] = datatable ;

//"Nameofyourchoice" will be the key of your session variable, next time when u click

DataTable dt= Getdatafromdatabase();

dt = (session["Nameofyourchoice"] as DataTable).Merge(dt);

session["Nameofyourchoice"] = dt;

datagrid1.datasource =(session["Nameofyourchoice"] as DataTable);
datagrid1.databind();




因此,由于dt =(session ["Nameofyourchoice"] as DataTable),因此每次点击都可以.Merge(dt);以前的结果是持续的.


Hi,
I am mani. I have a problem in display the data in datagrid.
What i did is I am creating a form and in this form i created a 6 textboxes and one search button. whenever the user enter a text in textbox i retrieve the data from the database according to the text the user entered and displayed in the datagrid.
The problem is when the user again enter the text in text box the datagrid is filled with new data and last data will be lost. But i want the newly searching data should be displayed in datagrid including the last retrieved data.

If anyone knows the way how it should be doing please reply me.

regards,
manikanta.

解决方案

1)If it is a windows application maintain previous result in DataTable variable and every time before binding the result add the result to the previous table and bind the table to datagrid,

2)If it is a web application u can do the same by maintaining the datatable in a session variable.


Hello sekharkaza,
If you dont mind can you give the an example to maintaing the datatable in session variable.


Mani,


 session["Nameofyourchoice"] = datatable ;

//"Nameofyourchoice" will be the key of your session variable, next time when u click

DataTable dt= Getdatafromdatabase();

dt = (session["Nameofyourchoice"] as DataTable).Merge(dt);

session["Nameofyourchoice"] = dt;

datagrid1.datasource =(session["Nameofyourchoice"] as DataTable);
datagrid1.databind();




so for each click because of dt = (session["Nameofyourchoice"] as DataTable).Merge(dt); previous result is sustained.


这篇关于在datagrid中显示数据时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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