如何在不重新调用数据库的情况下对数据进行分组.. [英] how to grouping data without re-calling from database..

查看:110
本文介绍了如何在不重新调用数据库的情况下对数据进行分组..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据表用户...

http://i61.tinypic.com/ 244b4o4.jpg [ ^ ]



i只想显示从组合框中选择的组...到列表视图

无需从数据库中重新查询...

if i点击从组合框中选择的组..

listview将只显示所选组...

任何想法??











thx for attention

i have a data table user...
http://i61.tinypic.com/244b4o4.jpg[^]

i want to show only selected group from combobox.. to the listview
without re query from database...
if i click selected Group from combobox..
the listview will show just the selected group...
any idea ??





thx for attention

推荐答案

你可以使用Linq查询:



1)将数据绑定到组合框:

You can use Linq query:

1) to bind data to combobox:
var qry = datatable1.AsEnumerable()
        .Where(r=>r.Field<string>("Role Group")=="Group01")
        .Select(r=>r.Field<string>("Role Group"));

ComboBox1.DataSource = qry;
ComboBox1.DisplayMember = "Name";
ComboBox1.ValueMember = "Name";





请参阅:使用DataTable和Linq绑定到ComboBox [ ^ ]



2)将数据绑定到listview:

使用与上面相同的逻辑。



See: Binding to a ComboBox using a DataTable and Linq[^]

2) to bind data to listview:
Use the same logic as above.

string comboval = combobox1.SelectedItem.ToString();
var qry = datatable1.AsEnumerable()
        .Where(r=>r.Field<string>("Role Group")==comboval);
DataTable dt = qry.CopyToDataTable();





注意,绑定数据的方式不同,因为ListView不能绑定到DataSource。



请参阅:数据绑定ListView [ ^ ]


尝试以下链接

http://stackoverflow.com/questions/13012585/how-i-can-filter-a-datatable [ ^ ]


这篇关于如何在不重新调用数据库的情况下对数据进行分组..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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