CodeSmith Community
Your Code. Your Way. Faster!

How do I implement a dual listbox against a many to many datasource.

Latest post 07-02-2008 4:15 AM by gordonj. 3 replies.
  • 06-25-2008 8:01 AM

    • gordonj
    • Top 150 Contributor
    • Joined on 03-26-2008
    • Posts 26
    • Points 530

    How do I implement a dual listbox against a many to many datasource.

    It is fairly straightforward to bind a many-to-many datasource to a conventional listbox or a checkbox list.  Behind the scenes these controls seem to know what has been selected and what has not, allowing for very simple binding.  An example of this is the auto-generated admin section produced by nettiers.

    I would like to produce a user control with dual listboxes and arrows to add and remove from the selected list.  I would like to be able to bind as simply as a conventional listbox.

    Has anyone done this and can they provide some advice?

    • Post Points: 35
  • 06-25-2008 11:12 AM In reply to

    • SuperJeffe
    • Top 25 Contributor
    • Joined on 05-05-2006
    • Tulsa, Ok
    • Posts 341
    • Points 8,575

    Re: How do I implement a dual listbox against a many to many datasource.

    I like to use this one.  I have done it a couple times.  I think you get the source code also so you could modify if need be.  It is a good example even if you don't like this control.

    http://www.metabuilders.com/Tools/DualList.aspx

    jeff

    ----------------------------------------------------------------------
     Member of the .NetTiers team | Visit http://www.nettiers.com
    ----------------------------------------------------------------------

    • Post Points: 60
  • 06-29-2008 9:09 AM In reply to

    • gordonj
    • Top 150 Contributor
    • Joined on 03-26-2008
    • Posts 26
    • Points 530

    Re: How do I implement a dual listbox against a many to many datasource.

    This looks like a great solution.

     I have managed to get the control set up and on the page.  I'm a bit confised though about how I bind to it.  Will I have to modify the control?

    Here is my code:

    <mbdl:DualList Id="BicSubjectDualList" runat="server"

    LeftDataSourceID="BicSubjectDataSource" LeftDataTextField="Description" LeftDataValueField="BicSubjectId"

    RightDataTextField="Description" RightDataValueField="BicSubjectId" />

     

    <data:BicSubjectDataSource ID="BicSubjectDataSource" runat="server" SelectMethod="GetAll" />

     

    <data:XrefContactBicSubjectDataSource ID="XrefContactBicSubjectDataSource" runat="server" SelectMethod="GetByContactId">

    <Parameters>

    <asp:QueryStringParameter Name="ContactId" QueryStringField="ContactId" Type="String" />

    </Parameters>

    </data:XrefContactBicSubjectDataSource>

     

    <data:ManyToManyListRelationship ID="XrefUserRoleRelationship" runat="server">

    <PrimaryMember ID="PrimaryMember1" runat="server"

    DataSourceID="ContactDataSource"

    EntityKeyName="ContactId" />

    <LinkMember ID="LinkMember1" runat="server"

    DataSourceID="XrefContactBicSubjectDataSource"

    EntityKeyName="ContactId"

    ForeignKeyName="BicSubjectId" />

    <ReferenceMember ID="ReferenceMember1" runat="server"

    DataSourceID="BicSubjectDataSource"

    ListControlID="BicSubjectDualList"

    EntityKeyName="BicSubjectId" />

    </data:ManyToManyListRelationship>

     

    I have basically substituted the DualList for the original Listbox.  I have set the left to my DataSource but I'm not sure how to get the right hand side into and out of the database. 

    The control is sitting in a form that is a template.

    Gordon

    • Post Points: 5
  • 07-02-2008 4:15 AM In reply to

    • gordonj
    • Top 150 Contributor
    • Joined on 03-26-2008
    • Posts 26
    • Points 530

    Re: How do I implement a dual listbox against a many to many datasource.

    Okay, I have a plan and would like some feedback on it if someone has time.

    If I place my dual control, as is, inside a user control and create a property to accept a DataSource, I should be able to wire up the selected and non selected items to the dual list and conversely get that list back out again when I submit the templated form.

    My question is, does this sound reasonable?  What is the generic datasource that all "data:BlahDataSources" inherit from?

    My confusion arises from not understanding how a list box can bind to a datasource and then use the many-to-many relationship to automatically select the current selections and also post any changes back without a code behind.

    I essentialy want to emulate this behaviour with the dual list.

    Must I pass my datasource and the m-m relationship or does the m-m relationship alter the datasource and provide some method of determining what has been selected, that I can access, alter and post back?

    • Post Points: 5
Page 1 of 1 (4 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems