I have a GridView which contains a TextField of BenefitName (string) and a ValueField of BenefitInfoKeySK (int).
Originally I directly bound a datasource to the combobox and had distinct TextField and ValueField values. (Code Sample 2)
I updated my code to create 'cascading' comboboxes and the TextField value no longer displays in my GridView but it does display within the comboBox in my edit form.
Why does the
TextFieldrender in my edit formcomboboxbut not on myGridView?
PartialView CodeSample 1 (Cascading combobox)
settings.Columns.Add(column =>
{
column.FieldName = "BenefitKey";
column.Name = "BenefitKey";
column.Caption = "Claim Type";
column.Width = 200;
column.Settings.AllowHeaderFilter = DefaultBoolean.False;
column.EditFormSettings.Visible = DefaultBoolean.True;
column.Settings.AllowSort = DefaultBoolean.False;
column.EditorProperties().ComboBox(p =>
{
p.CallbackRouteValues = new { Controller = "BenefitClaimDetails", Action = "GetBenefitTypes", TextField = "BenefitName", ValueField = "BenefitInfoKeySK", headerEmployeeID = Model.BenefitHeaderEmployee };
p.TextField = "BenefitName";
p.ValueField = "BenefitInfoKeySK";
p.ClientSideEvents.BeginCallback = "ClaimTypeComboBox_BeginCallback";
p.EnableCallbackMode = true;
p.Width = 200;
p.ValidationSettings.RequiredField.IsRequired = true;
p.ValidationSettings.RequiredField.ErrorText = "Claim Type cannot be blank";
p.ValidationSettings.ErrorDisplayMode = ErrorDisplayMode.ImageWithText;
});
});
PartialView Code Sample 2 (basic combobox)
settings.Columns.Add(column =>
{
column.FieldName = "BenefitKey";
column.Name = "BenefitKey";
column.Caption = "Claim Type";
column.Width = 200;
column.Settings.AllowHeaderFilter = DefaultBoolean.False;
column.EditFormSettings.Visible = DefaultBoolean.True;
column.Settings.AllowSort = DefaultBoolean.False;
column.ColumnType = MVCxGridViewColumnType.ComboBox;
var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
comboBoxProperties.Width = 200;
comboBoxProperties.DataSource = repository.GetBenefitListByEmployee(Model.BenefitHeaderEmployee);
comboBoxProperties.TextField = "BenefitName";
comboBoxProperties.ValueField = "BenefitInfoKeySK";
comboBoxProperties.DropDownRows = 15;
comboBoxProperties.ValueType = typeof(int);
comboBoxProperties.ValidationSettings.RequiredField.IsRequired = true;
comboBoxProperties.ValidationSettings.RequiredField.ErrorText = "Claim Type cannot be blank";
comboBoxProperties.ValidationSettings.ErrorDisplayMode = ErrorDisplayMode.ImageWithText;
});
I have found that p.TextField and p.ValueField in code sample 1 do nothing. They can be removed with no effect on the code. However I must pass those fields in my CallBackRoute and assign them in the controller code:
Controller Code
public ActionResult GetBenefitTypes(int claimantID, string textField, string valueField, string headerEmployeeID)
{
return GridViewExtension.GetComboBoxCallbackResult(p => {
p.TextField = textField;
p.ValueField = valueField;
p.BindList(repository.GetBenefitListByEmployee(claimantID, headerEmployeeID));
});
}
As you can see, at the end both techniques call the same Repository method. Please let me know if I can elaborate on anything.
EDIT
I also attempted to modify Code Sample 1 by adding a columnType value and assigning a data source as shown below. This successfully displayed the TextField on my GridView but the null which I pass for claimantID prevented the Editor combobox from displaying any values. For that reason I am also including the JS code where I assign claimantID.
Modified PartialView Code Sample 1 (working grid view, no values in combobox)
settings.Columns.Add(column =>
{
column.FieldName = "BenefitKey";
column.Name = "BenefitKey";
column.Caption = "Claim Type";
column.Width = 200;
column.Settings.AllowHeaderFilter = DefaultBoolean.False;
column.EditFormSettings.Visible = DefaultBoolean.True;
column.Settings.AllowSort = DefaultBoolean.False;
column.EditorProperties().ComboBox(p =>
{
p.CallbackRouteValues = new { Controller = "BenefitClaimDetails", Action = "GetBenefitTypes", TextField = "BenefitName", ValueField = "BenefitInfoKeySK", headerEmployeeID = Model.BenefitHeaderEmployee };
p.TextField = "BenefitName";
p.ValueField = "BenefitInfoKeySK";
p.ClientSideEvents.BeginCallback = "ClaimTypeComboBox_BeginCallback";
p.EnableCallbackMode = true;
p.Width = 200;
p.ValidationSettings.RequiredField.IsRequired = true;
p.ValidationSettings.RequiredField.ErrorText = "Claim Type cannot be blank";
p.ValidationSettings.ErrorDisplayMode = ErrorDisplayMode.ImageWithText;
});
column.ColumnType = MVCxGridViewColumnType.ComboBox;
var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
comboBoxProperties.DataSource = repository.GetBenefitListByEmployee(Model.BenefitHeaderEmployee, null);
comboBoxProperties.TextField = "BenefitName";
comboBoxProperties.ValueField = "BenefitInfoKeySK";
});
JS Code
@*The follwing functions handle the Cascading Benefit Type combobox*@
function OnSelectedClaimantChanged() {
BenefitClaimDetailsGridView.GetEditor("BenefitKey").PerformCallback();
}
function ClaimTypeComboBox_BeginCallback(s, e) {
e.customArgs["claimantID"] = BenefitClaimDetailsGridView.GetEditor("DependentKey").GetValue();
}
I'm sorry to include so much code and not a working project, but the Solution is quite large. I hope this will do.