我有一个
GridView
其中包含
TextField
属于
BenefitName
(
string
)和a
ValueField
属于
BenefitInfoKeySK
(
int
)。
原来我直接绑定了
datasource
到
combobox
并且有明显的
文本字段
和
ValueField值字段
价值观
(代码示例2)
我更新了代码以创建“级联”组合框
文本字段
值不再显示在我的
网格视图
但它确实显示在
comboBox
在我的编辑表单中。
为什么
文本字段
在我的编辑表单中渲染
下拉列表框
但是
不
在我的
网格视图
?
PartialView代码示例1
(级联组合框)
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代码示例2
(基本组合框)
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;
});
我发现了
p.TextField
和
p.ValueField
在代码示例1中,不执行任何操作。可以删除它们而不影响代码。然而,我必须通过我的
CallBackRoute
并在控制器代码中分配:
控制器代码
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));
});
}
正如您所看到的,最后这两种技术调用相同的
Repository
方法如果我能详细说明什么,请告诉我。
编辑
我还试图通过添加columnType值并分配数据源来修改代码示例1,如下所示。这成功显示了
文本字段
在我的
网格视图
但是
null
我认为
claimantID
阻止编辑器组合框显示任何值。因此,我还包括
JS
我分配的代码
索赔人ID
。
修改的PartialView代码示例1
(工作网格视图,组合框中无值)
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代码
@*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();
}
很抱歉,包含了这么多代码,而不是一个工作项目,但解决方案相当大。我希望这样就可以了。