I have my DD EF project with a filtered gridview in the List.aspx file. The gridview lists student attendance records and is filtered by the class the students are in which I do in the DomainService.cs file. When I attempt to insert a new attendance record
the details view (i.e. Details.aspx) has a drop down for the foreign key StudentID which lists all the students. So I want to filter the drop down list in much the same way the gridview is filtered.
I'm sorry I did not explain myself properly. I have my DD project with a filtered gridview in the List.aspx file. The gridview lists student attendance records and is filtered by the class the students are in. When I attempt to insert a new attendance record
the details view (i.e. Details.aspx) has a drop down for the foreign key StudentID which lists all the students. So I want to filter the drop down list in much the same way the gridview is filtered. Hope this helps.
Hi there, what you need to do is add the code for this filtering to the Get method of the entity in the domain service. You could create a custom field template but for me that defeats the object of the DS
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
The reason you woudl do it this way is all operation that are accessing that entity collection woudl then get the list pre-filtered. if this is not working add a break point in the Get method of the entity and see if the code is being executed correctly
:)
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
I must reiterate that if you are using Domain Service the Get shoudl always be called for any select query, your project must be at fault becase this is not happening I will make a sample and test and get back to you.
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
Hi there, I have just build a very simple Domain Service project sample and it works as I described. I believe your issue is that there is either somthing wrong with your Dynamic Data Domain Serive Project or there is some configuration wrong.
Example Project is here
DD_DS_Northwind.zip this is on my skydrive and so the link will simply take you to my public folder just look for the named zip file unzip and then configure the connection string, it's set for Northwind on (local) and run Open the Products edit insert
you will see categories is filtered to just items that begin with the letter 'C'.
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
I solved it. Here is what I did. I found out that the ForeignKey_Edit.ascx is the user control that has the foreign key dropdownlist. In the code behind there is a PopulateListControl() method. So I wrote my own PopulateListControl method and placed a condition
around the PopulateListControl() method as follows:
if (HttpContext.Current.User.IsInRole("Teacher"))
{
populateListControlStudentsFromaClass(DropDownList1);
}
else
{
PopulateListControl(DropDownList1);
}
Member
18 Points
187 Posts
How to apply a filter to a foreign key lookup in the Details View?
Jun 17, 2013 01:26 PM|mr41971|LINK
I have my DD EF project with a filtered gridview in the List.aspx file. The gridview lists student attendance records and is filtered by the class the students are in which I do in the DomainService.cs file. When I attempt to insert a new attendance record the details view (i.e. Details.aspx) has a drop down for the foreign key StudentID which lists all the students. So I want to filter the drop down list in much the same way the gridview is filtered.
All-Star
52673 Points
15719 Posts
Re: How to apply a filter to a foreign key lookup in the Details View?
Jun 17, 2013 01:35 PM|oned_gk|LINK
Suwandi - Non Graduate Programmer
Member
18 Points
187 Posts
Re: How to apply a filter to a foreign key lookup in the Details View?
Jun 17, 2013 02:39 PM|mr41971|LINK
I'm sorry I did not explain myself properly. I have my DD project with a filtered gridview in the List.aspx file. The gridview lists student attendance records and is filtered by the class the students are in. When I attempt to insert a new attendance record the details view (i.e. Details.aspx) has a drop down for the foreign key StudentID which lists all the students. So I want to filter the drop down list in much the same way the gridview is filtered. Hope this helps.
All-Star
17916 Points
5681 Posts
MVP
Re: How to apply a filter to a foreign key lookup in the Details View?
Jun 17, 2013 03:08 PM|sjnaughton|LINK
Hi there, what you need to do is add the code for this filtering to the Get method of the entity in the domain service. You could create a custom field template but for me that defeats the object of the DS
Always seeking an elegant solution.
Member
18 Points
187 Posts
Re: How to apply a filter to a foreign key lookup in the Details View?
Jun 17, 2013 03:14 PM|mr41971|LINK
I am not sure I follow. By the get method are you refering to:
If so then I think I did that:
All-Star
17916 Points
5681 Posts
MVP
Re: How to apply a filter to a foreign key lookup in the Details View?
Jun 17, 2013 03:54 PM|sjnaughton|LINK
The reason you woudl do it this way is all operation that are accessing that entity collection woudl then get the list pre-filtered. if this is not working add a break point in the Get method of the entity and see if the code is being executed correctly :)
Always seeking an elegant solution.
Member
18 Points
187 Posts
Re: How to apply a filter to a foreign key lookup in the Details View?
Jun 17, 2013 04:17 PM|mr41971|LINK
The filter is being executed for the gridview but not for the details view.
All-Star
17916 Points
5681 Posts
MVP
Re: How to apply a filter to a foreign key lookup in the Details View?
Jun 17, 2013 04:24 PM|sjnaughton|LINK
it should always be executed, that how a DS works it uses convention to call the Get method for all select queries.
Always seeking an elegant solution.
All-Star
52673 Points
15719 Posts
Re: How to apply a filter to a foreign key lookup in the Details View?
Jun 17, 2013 09:55 PM|oned_gk|LINK
Simply Pass ID and Class QueryString using HyperlinkField in GridView
Suwandi - Non Graduate Programmer
Member
18 Points
187 Posts
Re: How to apply a filter to a foreign key lookup in the Details View?
Jun 17, 2013 10:13 PM|mr41971|LINK
The StudentAttendance Table has the following fields:
ID, StudentID, Date, Present (boolean), and Late (boolean).
The ClassID is referenced from a Join table ClassStudents:
ID, ClassID, StudentID.
So in the DomainService.cs file I select a list of StudentIDs from a selected Class (ClassID).
As such I'm not sure your suggestion will work but I will try it. Thank you for you advice.
Member
18 Points
187 Posts
Re: How to apply a filter to a foreign key lookup in the Details View?
Jun 18, 2013 04:44 AM|mr41971|LINK
oned_gk I have tried and could not implement your suggestion. Thank you for your contribution.
All-Star
17916 Points
5681 Posts
MVP
Re: How to apply a filter to a foreign key lookup in the Details View?
Jun 18, 2013 04:59 AM|sjnaughton|LINK
I must reiterate that if you are using Domain Service the Get shoudl always be called for any select query, your project must be at fault becase this is not happening I will make a sample and test and get back to you.
Always seeking an elegant solution.
Member
18 Points
187 Posts
Re: How to apply a filter to a foreign key lookup in the Details View?
Jun 18, 2013 05:03 AM|mr41971|LINK
Thank you Steve.
All-Star
17916 Points
5681 Posts
MVP
Re: How to apply a filter to a foreign key lookup in the Details View?
Jun 18, 2013 05:30 AM|sjnaughton|LINK
Hi there, I have just build a very simple Domain Service project sample and it works as I described. I believe your issue is that there is either somthing wrong with your Dynamic Data Domain Serive Project or there is some configuration wrong.
Example Project is here DD_DS_Northwind.zip this is on my skydrive and so the link will simply take you to my public folder just look for the named zip file unzip and then configure the connection string, it's set for Northwind on (local) and run Open the Products edit insert you will see categories is filtered to just items that begin with the letter 'C'.
Always seeking an elegant solution.
Member
18 Points
187 Posts
Re: How to apply a filter to a foreign key lookup in the Details View?
Jun 20, 2013 03:58 AM|mr41971|LINK
I solved it. Here is what I did. I found out that the ForeignKey_Edit.ascx is the user control that has the foreign key dropdownlist. In the code behind there is a PopulateListControl() method. So I wrote my own PopulateListControl method and placed a condition around the PopulateListControl() method as follows:
Worked like a charm.
All-Star
17916 Points
5681 Posts
MVP
Re: How to apply a filter to a foreign key lookup in the Details View?
Jun 20, 2013 06:24 AM|sjnaughton|LINK
Hi there, this is a work around that I use when not using Domain Service.
Always seeking an elegant solution.