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

RadGrid, LINQ to SQL, master / detail design

1 Answer 144 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Richard Branham
Top achievements
Rank 1
Richard Branham asked on 26 Feb 2010, 06:57 PM
As an exercise to help me become more familiar with RadGrid and LINQ as well as master/detail pages, I am building an application which will help me to track a gear list for participants in a backpacking trip.  Hikers are required to obtain all of the items on the gear list.  I wish to create a page with a list of hikers in one grid and a list of gear items in another.  When the user clicks on the name of a hiker in one grid, the other grid will display a full list of gear items, each with a checkbox to indicate whether or not the item has been obtained by the selected hiker.  The user can check or uncheck items as needed.

I have created a simple DB which is depicted in the attached image.  I have also created a VS2008 web application which includes a DBML for the LINQ to SQL entities.  As this is an personal exercise, I have complete control of the DB and application code, so no options are off the table.

My particular question involves presenting the data to the user and recording their input (checking/unchecking gear items.)  As you can see from the diagram, I have tables for Person, Gear, and PersonGear.  Person contains a master list of hikers, Gear contains a master gear list, and PersonGear is a link table which holds a record for each piece of gear a person has obtained. 

How can I most efficiently present the gear records for a hiker and allow the user to check and uncheck boxes in a detail grid?  Will I have to bind the gear grid to the Gear table, include a checkbox column, then iterate through the records and set the checkbox value based on the presence or absence of a record in the PersonGear table, or is there a more straightforward approach that I'm missing?

Thanks in advance for your help.

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 03 Mar 2010, 04:58 PM
Hi Richard,

The option you first thought about is one way to go. You can have a GridTemplateColumn with a CheckBox control in the ItemTemplate. You would bind your details grid to the Gears table and then query the PersonGear records for the person selected in the Persons RadGrid. You can then iterate over those matching records, find the CheckBox control in every matching row for the detail table and set its Checked property to true.

There is also another option. You can use a little more complicated LINQ expressions to get all the records from the Gear table and additionally create a boolean field that will evaluate to TRUE if the current record from Gears has a related record in PersonGear, given a PersonID that is coming from the selected item in the Persons grid.

To demonstrate this, I have created a sample project using your data model. I have a single WebForms page with 2 RadGrids inside. The first RadGrid is bound to Persons. The second grid is bound to a custom LINQ query that returns a projection of all the fields in Gear + a boolean field set to true if there is a matching row in PersonGear. The matching itself is done with the respective Gear_ID from the Gear table, as well as the Person_ID coming from the selected item of the PersonsGrid.

This type of selection now allows me to simply bind the grid to the result of this query, where I have a GridTemplateColumn with a CheckBox in the ItemTemplate. The CheckBox is bound to the boolean field I created in the LINQ query. I have additionally implemented insertion of new records in PersonGear, which happens whenever you want to mark a piece of gear obtained by a person.

The sample project is attached along with the database. You only need to reference your Telerik.WEb.UI.dll assembly. Check it out.

Sincerely yours,
Veli
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Richard Branham
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or