Click here to Skip to main content
11,715,022 members (66,349 online)
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 18: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 Sergey Alexandrovich Kryukov 520
1 Richard MacCutchan 275
2 Maciej Los 259
3 ManasKumarM 155
4 Frankie-C 125
0 Sergey Alexandrovich Kryukov 775
1 CHill60 415
2 Richard MacCutchan 405
3 Maciej Los 389
4 OriginalGriff 320


Advertise | Privacy | Mobile
Web01 | 2.8.150901.1 | Last Updated 11 Sep 2012
Copyright © CodeProject, 1999-2015
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