Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 264
  • Last Modified:

LINQ query that needs further filtering

My query equijoins the selected attributes of the iea_foreign_course, the iea_foreign_school
and iea_country tables and compares the drop down selection (a country)to this join as a filter.
This data is bound to the gridview control to be displayed under the column names defined in the select paragraph.

I need the gridview to present these rows grouped by country.
using (DataClassesDataContext c = new DataClassesDataContext())
        {
            var schools = c.GetTable<iea_foreign_school>();
            var courses = c.GetTable<iea_foreign_course>();
            var countries = c.GetTable<iea_country>();
 
            var query =
                    from ct in countries
                    join s in schools
                        on ct.country_id equals s.country_id
                    join co in courses
                        on s.foreign_school_id equals co.foreign_school_id
                    where ct.country_name == DropDownList1.SelectedValue
                    select new
                    {
                        Partner_Number = co.foreign_course_num,
                        Partner_Title = co.foreign_course_name,
                        UNF_Course_Number = co.unf_course_num,
                        UNF_Course_Title = co.unf_course_name,
                        Status = co.course_status,
                        Start_End = co.start_end_date,
                        Language = co.language,
                    };
            if (query != null)
            {
                GridView1.DataSource = query;
                GridView1.DataBind();
            }
        }

Open in new window

0
pathfinder8008
Asked:
pathfinder8008
1 Solution
 
Sreedhar VengalaCommented:
Does not the query result is based on condition ct.countryname
I need the gridview to present these rows grouped by country ?  
0
 
naspinskiCommented:
just throw in an orderby
using (DataClassesDataContext c = new DataClassesDataContext())
        {
            var schools = c.GetTable<iea_foreign_school>();
            var courses = c.GetTable<iea_foreign_course>();
            var countries = c.GetTable<iea_country>();
 
            var query =
                    from ct in countries
                    join s in schools
                        on ct.country_id equals s.country_id
                    join co in courses
                        on s.foreign_school_id equals co.foreign_school_id
                    where ct.country_name == DropDownList1.SelectedValue
                    orderby ct.country_name
                    select new
                    {
                        Partner_Number = co.foreign_course_num,
                        Partner_Title = co.foreign_course_name,
                        UNF_Course_Number = co.unf_course_num,
                        UNF_Course_Title = co.unf_course_name,
                        Status = co.course_status,
                        Start_End = co.start_end_date,
                        Language = co.language,
                    };
            if (query != null)
            {
                GridView1.DataSource = query;
                GridView1.DataBind();
            }
        }

Open in new window

0
 
pathfinder8008Author Commented:
Thanks, he said while slapping forehead with open hand.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now