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

[Solved] Grid binding to a model property

1 Answer 111 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.
jmo
Top achievements
Rank 1
jmo asked on 28 Sep 2010, 03:34 PM
I have a grid within a larger page.

The page contains all properties of an object, and the grid is to contain a collection which is a property on the main object.

ie.

Person:
 - first name (string)
 - last name (string)
 - TelephoneNumbers (a list of telephone numbers)

I'd like to be able to bind the grid directly to the TelephoneNumbers property - is this possible?


1 Answer, 1 is accepted

Sort by
0
Adam Gritt
Top achievements
Rank 1
answered on 28 Sep 2010, 04:08 PM
Assuming that you have the Model for the page set to the Person object you could do something like this:

<%= Html.Telerik().Grid<TelephoneNumber>()
    .Name("PhoneNumbers")
    .BindTo(Model.TelephoneNumbers)
%>
assuming that the telephone numbers are a distinct object.

If you are using Ajax to switch the selected user instead of doing a postback you would have to setup the grid to use Ajax for its data binding instead of BindTo and then make a call such as:
$('#PhoneNumbers').data('tGrid').rebind({userId: $('#userid').val()});
to refresh the grid based on the new user id.  This is assuming you have the userid stored in a field named "userid" on the page.
Tags
Grid
Asked by
jmo
Top achievements
Rank 1
Answers by
Adam Gritt
Top achievements
Rank 1
Share this question
or