First of all, thanks for the quickness of your answer Stephen.
The code included in the article you've indicated in your answer is already in my application for quite a long time
and it has been working perfectly until a few weeks ago.
For a better contextualization, I'll give you a practical example: I have a Flight table, a CheckIn table and a FlightCheckIn table that associates Flight with CheckIn.
Inside the custom Flight/Edit.aspx page I have a gridview that shows all the FlightCheckIn records where the FlightID column is equal. When you click the 'Insert New Item' link, a FormView appears below, with a dropdown list of all the checkins available
to associate with the given flight.
This is the point where I'm having the problem:
- If I apply the HideColumnIn attribute, the column Flight is correctly hidden, but when the user presses the Insert link, the record is not inserted in the database, because the value of the hidden column is 0.
- If I remove the HideColumnIn attribute, the column Flight appears (which is not desirable) as a dropdown list with all the flights available, but the user can insert with sucess a new record.
It's driving me crazy, and I cannot understand what's going on, and how to solve this problem...
OK, I managed to fix this situation, but not using the insert parameter.
Based on that tip, I managed to find a way to set the correct value: when the OnInserting event - from the FromView - is executed, I set the empty EntityID to the value of the ID passed in the query string from the request.
Thanks for the help.
Cheers.
Marked as answer by rreal on Jan 03, 2012 05:52 PM
rreal
Member
4 Points
3 Posts
Problem hiding Foreign Key
Dec 27, 2011 05:30 PM|LINK
Hi.
I´m having some trouble hiding a column in a FormView inside a Edit page from an Entity.
public class FlightStopMetadata { [Display(Name = "Airport")] [FilterUIHint("Autocomplete")] [UIHint("Autocomplete")] public object Airport { get; set; } [HideColumnIn(PageTemplate.Edit, PageTemplate.Insert)] public object Flight { get; set; } }If I use the HideColumnIn attribute - http://csharpbits.notaclue.net/2010/02/new-way-to-do-column-generation-in.html - or ScaffoldColumn
attribute to hide the column in the FormView, the entity won't be saved because the value of the column will always be null (or zero).
If I remove those attributes, I can insert new records, because that column is with a proper value, but the Flight column appears in the
FormView.
I've searched everywhere for a solution for this problem, and I've tried several aproaches to this situation, and none of them worked,
but what suprises me the most is that I only have this problem recently and I don't no what is causing it.
Can anyone help me?
sjnaughton
All-Star
27330 Points
5459 Posts
MVP
Re: Problem hiding Foreign Key
Dec 28, 2011 02:48 PM|LINK
Hi Rreal, have a look at my article here A New Way To Do Column Generation in Dynamic Data ... the sample project actually has this in there.
Always seeking an elegant solution.
rreal
Member
4 Points
3 Posts
Re: Problem hiding Foreign Key
Dec 30, 2011 11:37 AM|LINK
First of all, thanks for the quickness of your answer Stephen.
The code included in the article you've indicated in your answer is already in my application for quite a long time
and it has been working perfectly until a few weeks ago.
For a better contextualization, I'll give you a practical example: I have a Flight table, a CheckIn table and a FlightCheckIn table that associates Flight with CheckIn.
Inside the custom Flight/Edit.aspx page I have a gridview that shows all the FlightCheckIn records where the FlightID column is equal. When you click the 'Insert New Item' link, a FormView appears below, with a dropdown list of all the checkins available to associate with the given flight.
This is the point where I'm having the problem:
- If I apply the HideColumnIn attribute, the column Flight is correctly hidden, but when the user presses the Insert link, the record is not inserted in the database, because the value of the hidden column is 0.
- If I remove the HideColumnIn attribute, the column Flight appears (which is not desirable) as a dropdown list with all the flights available, but the user can insert with sucess a new record.
It's driving me crazy, and I cannot understand what's going on, and how to solve this problem...
Thanks in advance
sjnaughton
All-Star
27330 Points
5459 Posts
MVP
Re: Problem hiding Foreign Key
Dec 30, 2011 06:11 PM|LINK
if these are on the same page then you will need to add insert parameter to the insert form data source with the FK value etc.
Always seeking an elegant solution.
rreal
Member
4 Points
3 Posts
Re: Problem hiding Foreign Key
Jan 03, 2012 05:52 PM|LINK
OK, I managed to fix this situation, but not using the insert parameter.
Based on that tip, I managed to find a way to set the correct value: when the OnInserting event - from the FromView - is executed, I set the empty EntityID to the value of the ID passed in the query string from the request.
Thanks for the help.
Cheers.