简体   繁体   中英

Telerik MVC3 Grid - is it possible to use Template and ClientTemplate at the same time?

Is it possible to use a Template and a ClientTemplate at the same time?

I want to do a bool check in the Template but don't know how to pass it to the checkbox in the ClientTemplate when there is no binding.

    @(Html.Telerik().Grid(Model.Item)
     .Name("Grid")
     .Columns(column =>
       column.Template(x => x.ItemId.Equals(Model.Id))
             .ClientTemplate("<input type='checkbox' checked='<#=????? #>' disabled />");
    })

Maybe there's another way to achieve this?

Template is used for server binding, while ClientTemplate is used for ajax or web service binding. If you are using server binding, ClientTemplate is not used. If you are using ajax binding, Template is not used. With ClientTemplate, you can use <#= #> to embed databound expressions in a similar way to server side Template.

.ClientTemplate("<input type='checkbox' checked='<#= (ItemID == Id) #>' disabled />")

What you put in a conditional is limited. I have been able to successfully use a bool and an int comparison, but not a string comparison.

For this particular case, you don't have to use Template . You can use the embedded databound functionality (as mentioned by Daniel) of the ClientTemplate to achieve what you want,

@(Html.Telerik().Grid(Model.Item)
  .Name("Grid")
  .Columns(column =>
    column.ClientTemplate("<input type='checkbox' checked='<#=ItemId == " + Model.Id + "#>' disabled />");
})

This way you passed the variable Model.Id from the server, while the actual comparison is down using Javascript at the client side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM