View Single Post
  #18 (permalink)  
Old August 29th, 2012, 05:26 AM
Imar's Avatar
Imar Imar is offline
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Quote:
by the way, our country has more than 75 provinces so i handcoded and copy-pasted them one by one.
Really? Wow! What a nightmare that must be if you ever want to change something.

What about this:

Code:
Dim ProvinceMunicipalities = From city In myEntities.CityTbls
                                        Where city.Province = Province_Ddl.SelectedValue 
                                        Order By city.City
                                        Select city.City

                cityGridView.DataSource = ProvinceMunicipalities
                cityGridView.DataBind()
Not it works for all 75 of them, regardless of what you choose in the DDL.

To make this even easier, set up the data source for the GridView to use the SelectedValue of the DropDownList. This way, you can accomplsih the exact same thing without manual coding and just a few server controls.

You find an example that demonstrates exactly this (using Genres and Reviews) on page 446 and further in the section "Filtering Data".

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
rmanapul (August 29th, 2012)