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

[Solved] Binding Grid editing template

0 Answers 96 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.
Pål
Top achievements
Rank 1
Pål asked on 17 Jan 2011, 02:07 PM
Hi,

I have a view strongly typed to a viewmodel object. The viewmodel contains an object of type Loan which has a list of LoanEvent objects. In the view I have a grid that is populated with the LoanEvent list. When inserting a LoanEvent I need one of the fields to be set to the name of the currently logged on user. Not username but FullName which is a property on a object called Officer in my model. There is a mapping between logged on user and the Officer user object.

I was thinking that an editor template could be used.

My View

<%: Html.Telerik().Grid(Model.Loan.LoanEvents)
    
.Name("LoanEvents") 
    .DataKeys(keys => keys.Add(le => le.ID))
    
.ToolBar(commands => 
commands.Insert())
    
.DataBinding(databinding => databinding.Server() 
            .Select("Details", "Loan", new {id = Model.Loan.ID})
            
.Insert("Create", 
"LoanEvent", new { id = Model.Loan.ID })
            
.Update("Save", "LoanEvent")
            
.Delete("Delete", "LoanEvent"))
    
.Columns(columns =>
            columns.Bound(p => p.Created).Width(115).Format("{0:d}"); 
            columns.Bound(p => p.Action).Width(130).Title("Type"); 
            columns.Bound(p => p.Comment).Width(150).Title("Kommentar"); 
            columns.Bound(p => p.Officer).Width(130).Title("Rådgiver"); 
            columns.Command(commands =>
                                
commands.Edit(); 
                                commands.Delete();
                                }).Width(180).Title("");
            })
    
.Editable(editing 
=> editing.Mode(GridEditMode.InLine))
    
.Pageable(paging => 
paging.PageSize(10))
    
.Sortable()
    
.Filterable()
%>

How can I create an editor template where p.Officer can point to the FullName of the Officer object. When saving the new LoanEvent I need to store it as the foreignkey of the user object.

Any help would be appreciated.

Best regards
Pål Eilertsen
Tags
Grid
Asked by
Pål
Top achievements
Rank 1
Share this question
or