Ajith
Ajith

Reputation: 393

Kendo combobox not show the Text corresponding to value from modal

I have a partial view with a combobox. When try to render partial view with modal(contains data from database), it shows only the value field. i want to show the text field of that value field. Help me please.

@(Html.Kendo().ComboBoxFor(m => m.divCode)
    .DataTextField("Name")
    .DataValueField("ID")                                        
    .HtmlAttributes(new { style = "width:160px" })
    .SelectedIndex(0)
    .AutoBind(false)
    .Placeholder("Select Div Code")
    .Filter(FilterType.Contains)
    .DataSource(source =>
    {
        source.Read(read =>
        {
            read.Action("GetDivision", "AssetTransaction");
        });
    })
)

Upvotes: 2

Views: 2217

Answers (3)

Tawab Wakil
Tawab Wakil

Reputation: 2323

You can set AutoBind to false (which you've already done), and then use the Text property to define the text that will be displayed:

@(Html.Kendo().ComboBoxFor(m => m.divCode)
.DataTextField("Name")
.DataValueField("ID")                                        
.HtmlAttributes(new { style = "width:160px" })
.SelectedIndex(0)
.AutoBind(false)
.Text(Model.YourTextFieldToDisplay)  // add this and modify to your needs
.Placeholder("Select Div Code")
.Filter(FilterType.Contains)
.DataSource(source =>
{
    source.Read(read =>
    {
        read.Action("GetDivision", "AssetTransaction");
    });
})

Upvotes: 0

irgnosis
irgnosis

Reputation: 91

I was facing similar issue since my model has attribute for code.

I changed

AutoBind(false) 

to

AutoBind(true). 

Now it shows the Text instead of the Value

Upvotes: 1

Rajeshkumar Kandhasamy
Rajeshkumar Kandhasamy

Reputation: 6461

There is no fault i found with your view code. Its just looks fine to me. I think you are doing same as this sample.

I suspect your value assignment to c.divisioncode, Name = c.divisionname. Just make sure you are getting and setting value and text properly From your db service calls to view model and assigning correctly. For that you can use and see the "quick watch" while debugging the GetDivision "Action" in AssetTransaction "controller".

Sample Code i found:

@(Html.Kendo().ComboBox()
          .Name("products")
          .DataTextField("ProductName")
          .DataValueField("ProductID")
          .HtmlAttributes(new { style = "width:250px" })
          .Filter("contains")
          .AutoBind(false)
          .MinLength(3)
          .DataSource(source => {
              source.Read(read =>
              {
                  read.Action("GetProducts", "Home");
              })
              .ServerFiltering(true);
          })
    )

Upvotes: 1

Related Questions