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

[Solved] Many to Many relationship and multiple data in single row

0 Answers 36 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Dario
Top achievements
Rank 1
Dario asked on 28 May 2012, 10:40 PM
Hi. I've been searching through Telerik pages and Google for a solution to this but haven't found anything really that would help me, so here it goes.
I made a model with Telerik ORM and am using a Grid to show data.
I have one many-to-many relationship between two tables (Books and Borrowing - application is for a library).
If I want to access a list of books that are associated with a single borrowing i can do this by referencing an association between those tables. Association returns a list of Book objects, and from there I can access a single book and all of its property's.

What I want is to be able to show all of the books associated with a single borrowing in one row. One row for one borrowing in a Grid that binds its data from Borrowings table.
Best I could manage is to index the association witch returns a single book, like so:
Borrowings.Books[0].ID
But I don't know how to go through the entire list of Books (through all the indexes that the association returns) and write, say, the Author of all related Books in a single row (which represents a single borrowing).

I tried using a for and foreach loops but don't know how to put them inside a grid (if that's even possible), and I was looking at IEnumerator/GetEnumerator() but don't know if I'm using it right. I am pretty new to Telerik extensions for MVC btw.

Tnx for your answers and any help would be appreciated.


Edit:
If anyone's interested, I have managed to find a way of some sorts. This is the code I used:
.CellAction(cell =>
        {
            if (cell.Column.Title == "Books")
            {
                for (int i = 0; i < cell.DataItem.Books.Count; i++)
                {
                    if(i%2 == 1){
                        cell.Text += "<div style='color:Red'>" + cell.DataItem.Books[i].Title + "</div>";
                    }else{
                        cell.Text += "<div style='color:Blue'>" + cell.DataItem.Books[i].Title + "</div>";
                    }
                }
            }
        })
Tags
Grid
Asked by
Dario
Top achievements
Rank 1
Share this question
or