This is a migrated thread and some comments may be shown as answers.

Many-To-Many Mappings in a single cell

1 Answer 73 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 09 Sep 2008, 01:43 AM
What is the best way to handle a many-to-many mapping in the DB for a table that is being represented with the Grid control using databinding?

Let's say I have a employee contact table and it currently has a FK for ContactTypeID which is a lookup to one of a variety of contact types.

Currently it is a databound dropdown list in the grid.  But let's say that I want to make it a many to many mapping by inserting a mapping table called EmployeeContacts which contains a FK to Employee table and a FK to ContactTypes table.

I still want a single grid that shows and edits employee contacts from the Employee table, but I now want the column that used to be a simple drop down of Contact Types to be a drop down with multiple check boxes or some other kind of column that lets me choose more than one selection.  Then I want to keep as much of the databinding as possible, or do I have to manually code the back end hook up of the checking and recording of the checkboxes upon edit form submission?

Anybody have an example of this kind of usage with RadGrid?  m2m mapping tables are a pretty common need.

Thanks in advance,
Rob

1 Answer, 1 is accepted

Sort by
0
Bodevain Svensson
Top achievements
Rank 1
answered on 11 Sep 2008, 12:20 PM
Let me give you my opinion here, Rob.

Indeed many-to-many mappings are commonly used when database tables are involved, no doubt about that. In order to display the data fetched from a Select query which spans over several tables, I would go with the VS GridView control first and put a dropdown list inside item/edit template of template column. I suppose that this combobox can be bound either declaratively through a data source control (when DataSourceID is assigned to it) or programmatically inside the RowDataBound handler of the GridView.

Once you are ready with the implementation, use the information from this white paper on the Telerik site in order to transform the code for their web grid control. This should be pretty much all you have to do.

To allow more than one option for end user selection in the dropdown, utilize RadComboBox as shown in this demo (the first dropdown control):

http://demos.telerik.com/ASPNET/Prometheus/ComboBox/Examples/Default/DefaultCS.aspx

Bodevain
Tags
Grid
Asked by
Rob
Top achievements
Rank 1
Answers by
Bodevain Svensson
Top achievements
Rank 1
Share this question
or