1

以下是我在 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;
4

2 回答 2

2

目前 MVC ComboBox 扩展不允许将“Null Item”(Null Text,Water Mark)添加到 Items 集合中。它在 DevEx TO-DO 列表中。

你可以试试这个解决方法。

 @Html.DevExpress().ComboBox(edtSettings =>
            {
    edtSettings.Properties.ClientSideEvents.Init = "function(s,e){if(s.GetValue()=='0'){ s.SetValue(null);} }";
...
于 2013-06-05T19:50:09.367 回答
1

ComboBox中,您可以使用此属性:

edtSettings.Properties.NullDisplayText = "Please Choose and Employee";
于 2013-03-07T14:42:12.920 回答