Kelly Cline
Kelly Cline

Reputation: 2246

Set initial combobox selection DevExpress Razor

I simply want to have the "Area" value (which is one of the items) be selected when the view appears. This is what I have:

@Html.DevExpress( ).ComboBox( settings =>
{
    settings.Name = "cmbFieldLevel";
    settings.CallbackRouteValues = new { Controller = "Equipment", Action = "FieldLevelPartial" };
    settings.Properties.ValueType = typeof( string );
    settings.Properties.TextField = "AreaName";
    settings.Properties.ValueField = "AreaID";
    settings.Properties.EnableClientSideAPI = true;
    settings.ClientSideEvents.DataBound = "function( s, e ){ cmbFieldLevel.SelectedItem = "Area"; } ";
}).BindList(FieldLevel.GetAreaFilters()).GetHtml()

Any clues?

Upvotes: 1

Views: 4894

Answers (1)

SerenityNow
SerenityNow

Reputation: 1065

2 ways I can think of.

  1. If you change your ComboBox to ComboBox for you can specify the model's value

like so

@Html.DevExpress().ComboBoxFor(x => x.ParamOrderNo, settings =>
{
      settings.Properties.ValueField = "OrderNo";
      settings.Width = 200;
      settings.Properties.TextField = "Name";
}).BindList(CeduleProductionMVC.ViewModels.ViewModelCeduleGlobale.GetCommandes()).GetHtml()
  1. Also, you can set the SelectedIndex, if your combolist content is fixed, the index might always be the same everytime all the time. Also, If you list is not fixed, you might be able to make a method to retrieve the index and set in after that.

Upvotes: 1

Related Questions