asp.net-mvckendo-uikendo-asp.net-mvckendo-multiselect

Kendo Multiselect with composite dataTextField


I'd appreciate if someone could advise on the following:

My Multiselect:

 @Html.Kendo().MultiSelectFor(model => model.PAYMENT_METHOD).BindTo(paymentMethods).DataTextField("TITLE").DataValueField("CODE")

The dataSource looks like this:

CODE     TITLE
  1       abc
  2       def

Is it possible to have composite DataTextField , specifically like: 1 - abc, 2 - def, etc., i.e "CODE" - "TITLE"?

I know I could create a select list and define the format of textfield, but maybe there is another way? Thanks!


Solution

  • You could specify a template for the display item (you would probably want to take the text field out then):

     @Html.Kendo().MultiSelectFor(model => model.PAYMENT_METHOD)
                  .BindTo(paymentMethods)
                  //.DataTextField("TITLE")
                  .DataValueField("CODE")
                  .ItemTemplate("#= CODE# #=' - '# #= TITLE#")
    

    Here's the link to the ItemTemplate method and the link to the general template methods.