以下是我在 dev express 网格视图编辑模板中使用的组合框代码。我希望组合框在添加新员工时不显示任何内容或显示“请选择和员工”的字符串,而不是在编辑时显示。
@Html.DevExpress().ComboBox(edtSettings =>
{
edtSettings.Width = 200;
edtSettings.Name = "EmployeeID";
//edtSettings.Properties.TextField = "FirstName";
edtSettings.Properties.ValueField = "EmployeeID";
edtSettings.Properties.ValueType = typeof(int);
edtSettings.Properties.DropDownStyle = DropDownStyle.DropDownList;
edtSettings.ShowModelErrors = true;
edtSettings.Properties.TextFormatString = "{0}" + " " + "{1}";
edtSettings.Properties.Columns.Add("FirstName", "First Name", 150);
edtSettings.Properties.Columns.Add("LastName", "Last Name", 150);
//--- For client side validations
edtSettings.Properties.ValidationSettings.RequiredField.IsRequired = true;
edtSettings.Properties.ValidationSettings.RequiredField.ErrorText = "An Employee must be selected from the list.";
}).BindList(Model.NonUsers).Bind(Model.UserSingle.EmployeeID).GetHtml()
我这样做是为了传递正确的 Model.UserSingle,如下所示
var User = ViewData["UserDetail"] != null
? ViewData["UserDetail"]
: !c.Grid.IsNewRowEditing
? Model.UserList.FirstOrDefault(m => m.EmployeeID == Convert.ToInt32(DataBinder.Eval(c.DataItem, "EmployeeID")))
: new User
{
SiteID = (int)Session["siteID"],
////employee ID cant set to blank, keeps adding a zero
//EmployeeID = Convert.ToInt32(null),
//this is defaulted to 'Timesheet Only'
UserGroupID = 3
};
Model.UserSingle = (User)User;