Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Sorting combobox
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.
Posted 10-Sep-12 19:51pm
Comments
VijayChauhan123 at 11-Sep-12 1:06am
   
yes you can do it just by plain sql
VijayChauhan123 at 11-Sep-12 1:07am
   
Just write your code in the selectedIndex event of the first combobox.
ridoy at 11-Sep-12 1:19am
   
you can do it in both ways..only sql or only LINQ can do it.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 400
1 Sergey Alexandrovich Kryukov 329
2 Afzaal Ahmad Zeeshan 264
3 BillWoodruff 245
4 CPallini 195
0 OriginalGriff 5,560
1 DamithSL 4,476
2 Maciej Los 3,942
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 11 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100