如何根据另一个组合框选择过滤一个组合框? [英] How to filter one combobox based on another combobox selection?

查看:115
本文介绍了如何根据另一个组合框选择过滤一个组合框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试过滤用来自本地sqlserverce数据库的数据填充的组合框.我的任务是在一个组合框中选择一个索引,并用结果过滤下一个组合框. LINQ可以解决这个问题吗?还是可以仅使用普通的SQL来做到这一点?我正在将Visual Studio 2010/2012与SQL Server CE Edition一起使用.不胜感激.

I am trying to filter comboboxes populated with data from a local sqlserverce database. My task is to select one index in one combobox and have that result filter the next combobox. Would LINQ work for this or can I do it with just plain SQL? I am using Visual Studio 2010/2012 with SQL Server CE Edition. I would appreciate any help.

推荐答案



当然,您可以在其中使用linq.

试试这个,

Hi,

ofcourse you can use linq in this.

try this,

protected void combobox1_selectedIndexChanged(object sender, EventArgs e)
{
   //DataSet Objs holds data from sql server with two datatables one is source for combobox1 and other is source for combobox2
   DataTable dt = (from val in Objds.Tables[2].AsEnumerable() where val.Field<string>("Column1")== combobox1.SelectedValue select val).CopyToDataTable();

combobox2.DataTextField="Column2";
combobox2.DataValueField="Column1";
combobox2.DataSource = dt;

}



希望对您有所帮助.



hope it helps.




检查一下.
http://social.msdn.microsoft.com/Forums/eu/csharplanguage/thread/b888969e-bb8e-44e3-a83d-b576425c4e13 [
Hi,

Check this out.
http://social.msdn.microsoft.com/Forums/eu/csharplanguage/thread/b888969e-bb8e-44e3-a83d-b576425c4e13[^]

Hope this helps.


这篇关于如何根据另一个组合框选择过滤一个组合框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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