locked
Problem hiding Foreign Key RRS feed

  • Question

  • User-1900316182 posted

    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?

    Tuesday, December 27, 2011 1:30 PM

Answers

  • User-330204900 posted

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 28, 2011 10:48 AM
  • User-330204900 posted

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 30, 2011 2:11 PM
  • User-1900316182 posted

    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 Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 3, 2012 1:52 PM

All replies

  • User-330204900 posted

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 28, 2011 10:48 AM
  • User-1900316182 posted

    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 Wink 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

    Friday, December 30, 2011 7:37 AM
  • User-330204900 posted

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 30, 2011 2:11 PM
  • User-1900316182 posted

    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 Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 3, 2012 1:52 PM