locked
Many-To-Many Edit template in insert mode RRS feed

  • Question

  • User-1442747414 posted

    I have a many to many relationship in one of my entities. The ManyToMany_Edit.ascx template appears to render only in case of detail and edit mode, but does not show in insert mode. Is this the expected behavior? Has anyone else come across this?

    Thursday, February 17, 2011 4:07 PM

Answers

  • User232504566 posted

    I have what i think is a pretty easy solution.

    I created an Insert Entity Template page for the table with the many to many relationship. From there i was able to add the navigation property as a dataField. From that point when you go to any place to insert, the many to many field is there ready to be inserted. I changed the check boxs to a multi select listBox because some of my tables have a lot of values.

    I guess this only works in EF but was really an easy solution for me.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 24, 2011 11:19 AM

All replies

  • User-330204900 posted

    Hi  we have disscused this before on this forum and there's not an easy solution.

    Thursday, February 24, 2011 10:32 AM
  • User232504566 posted

    I have what i think is a pretty easy solution.

    I created an Insert Entity Template page for the table with the many to many relationship. From there i was able to add the navigation property as a dataField. From that point when you go to any place to insert, the many to many field is there ready to be inserted. I changed the check boxs to a multi select listBox because some of my tables have a lot of values.

    I guess this only works in EF but was really an easy solution for me.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 24, 2011 11:19 AM
  • User-330204900 posted

    Hi Blastdan,any chance of posting some sample code?

    Friday, February 25, 2011 8:03 PM
  • User232504566 posted

    Alright will have to be on Monday Tho!

     

     

    Friday, February 25, 2011 8:04 PM
  • User232504566 posted

    Alright So ill see what i can do to explain what i did.

    I have a table Called Service Providers and one called Contacts Between there is a junction Table. So Service Provder 1 - * Provider_contact * - 1 Contact. Fairly simple stuff there.

    I used auto scaffolding with dynamic data wich gave service provider a navigation property called Contacts, and Contact a nagivation property called ServiceProviders. At first i was annoyed that this created checkboxes. I had far too many service providers and contacts to have a checkbox for each one. So I edited both the ManyToMany and ManyToMany_Edit Field templates.

    ManyToMany

     

    <div style="overflow:scroll; height:50px; overflow-x: hidden;">
    <asp:Repeater ID="Repeater1" runat="server">
       
    <ItemTemplate>
         
    <asp:DynamicHyperLink runat="server"></asp:DynamicHyperLink><br />
       
    </ItemTemplate>
    </asp:Repeater>
    </div>

     

    This kept the hyperlinks but created a nice scroll box effect in each cell, really worked out very nicely.

     

    ManyToMany_Edit

     

    <asp:ListBox ID="ListBox1" runat="server" ondatabound="ListBox1_DataBound" 
       
    SelectionMode="Multiple"></asp:ListBox><br />

    <ajaxToolkit:ListSearchExtender id="LSE" runat="server"
       
    TargetControlID="ListBox1"
       
    PromptText="Type to search"
       
    PromptCssClass="ListSearchExtenderPrompt"
       
    PromptPosition="Top"
       
    IsSorted="true"/>


    <asp:LinkButton ID="LinkButton1" runat="server"></asp:LinkButton>

     

    As you can see my Multi Line search i added a search from the ajax tool kit making finding new values pretty sweet. In the code behind all i had to do was switch dropdownbox1 with the ID of the multiLine Box, and make sure that if you drag and drop you set the property to multi select.

     

    The next part was to create the Entity Template for both ServiceProvider and Contact. Ill only show one as they are both the same. It was as simple as using a dynamicControl and setting the dataField to the navigation property that was created by auto scaffolding.

     

                <td class="DDLightHeader">
                   
    <asp:Label ID="Label29" runat="server" Text="ServiceProviders" />
               
    </td>
               
    <td>
                   
    <asp:DynamicControl ID="DynamicControl29" runat="server" DataField="ServiceProviders" Mode="Insert" />
               
    </td>

     

    This is for the Contact Entity Template and was name Contact_Insert.ascx

    Now when you go to create a new contact you will have a Seachable multi select box with all the unique serviceProviders to choose from.

     

    I hope that Helps!

    Monday, February 28, 2011 9:45 AM
  • User371385042 posted

    Hi Blastdan,

    Great work, It is just that solution, that I was looking for, but I'm new on this and have the same isue that a customer want all the stuff on insert.

    I really been fighting to understand how implement your code, but I don't how to implement it into my project.

    Can you come with more hints on what to get this working or examples?

    gothardt

    Tuesday, March 1, 2011 5:24 AM
  • User232504566 posted

    I wouldnt mind giving some more insight into what is going one.
    would you mind stateing what it is exactly that your having trouble understanding?

    Wednesday, March 2, 2011 8:56 AM
  • User371385042 posted

    Hi,

    Great with some help, thanks Smile

    In my solution I use EF and dynamic data site, and added some user security. I used the method from:

    http://csharpbits.notaclue.net/2008/05/dynamicdata-attribute-based-security.html

    The problem is that I have many to many properties on the item and they doesn't show up on insert new item. You can only see when you have clicked on save. And then edit item and then they show up.

    I have googled and strugled with the dynamic data site, but I cant find the transparent in how to add the functionality in the entity class or any other way.

    I just get the idea on how to, it would help, because right I'm stucked.

    Thursday, March 3, 2011 3:20 AM
  • User232504566 posted

    It sounds like you have yet to create an entity template for your table

    http://msdn.microsoft.com/en-us/library/dd723645.aspx

    thats a great resource on getting started with entity templates. Once you have the entity template set up then on {table}_Insert make sure the entity navigation property has the mode=Insert and your on your way.

    Thursday, March 3, 2011 9:29 AM