Ticket T137075
Visible to All Users

GridView - Batch Edit - How to implement custom validation

created 11 years ago (modified 8 years ago)

Hello,

How to implement server side validation control in Grid View. for your reference i am attaching snapshot.

C#
@Html.DevExpress().GridView(settings => { settings.Name = "ProfileGrid"; settings.Width = System.Web.UI.WebControls.Unit.Percentage(100); settings.Columns.Add(column => { column.Caption = Bixi_Atlas_Client_MVC_TicketPortal_MA_Localization.resActive; column.FieldName = "IsProfileActive"; column.SetDataItemTemplateContent(c => { Html.DevExpress().CheckBox(dSettings => { dSettings.Name = "IsProfileActiveP" + c.KeyValue; dSettings.Properties.ClientSideEvents.ValueChanged = String.Format("function (s, e) {{ OnValueChanged(s, '{0}', '{1}', '{2}'); }}", c.Column.FieldName, c.KeyValue, Url.Action("UpdateProfileValue", "ManageAccess", null)); // dSettings.Width = Unit.Pixel(60); dSettings.Width = System.Web.UI.WebControls.Unit.Percentage(100); }).Bind(DataBinder.Eval(c.DataItem, c.Column.FieldName)).Render(); }); }); settings.Columns.Add("ProfileName", Bixi_Atlas_Client_MVC_TicketPortal_MA_Localization.resProfile); settings.Columns.Add(column => { column.FieldName = "AccessType"; column.Caption = Bixi_Atlas_Client_MVC_TicketPortal_MA_Localization.resAccessType; column.ColumnType = MVCxGridViewColumnType.ComboBox; var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties; column.SetDataItemTemplateContent(c => { Html.DevExpress().ComboBox(editorSettings => { editorSettings.Name = "comboAccesss" + c.VisibleIndex; editorSettings.Properties.TextField = "DisplayName"; editorSettings.Properties.ValueField = "Value"; editorSettings.Properties.ValueType = typeof(Bixi.Atlas.Client.MVC.TicketPortal.ManageAccess.Enums.AccessType); editorSettings.Width = System.Web.UI.WebControls.Unit.Percentage(100); editorSettings.Properties.ClientSideEvents.ValueChanged = String.Format("function (s, e) {{ OnValueChanged(s, '{0}', '{1}', '{2}'); }}", c.Column.FieldName, c.KeyValue, Url.Action("UpdateProfileValue", "ManageAccess", null)); }).BindList(ViewBag.AcessType) .Bind(DataBinder.Eval(c.DataItem, "AccessType")).Render(); }); }); settings.Columns.Add(column => { column.FieldName = "WeeklyPlanID"; column.Caption =Bixi_Atlas_Client_MVC_TicketPortal_MA_Localization.resWeeklyPlan; column.ColumnType = MVCxGridViewColumnType.ComboBox; var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties; column.SetDataItemTemplateContent(c => { Html.DevExpress().ComboBox(editorSettings => { editorSettings.Name = "comboWeeklyPlant" + c.VisibleIndex; editorSettings.Properties.TextField = "WEEKLYPLAN_NAME"; editorSettings.Properties.ValueField = "WEEKLYPLAN_ID"; editorSettings.Properties.ValueType = typeof(Guid); editorSettings.Width = System.Web.UI.WebControls.Unit.Percentage(100); editorSettings.Properties.ClientSideEvents.ValueChanged = String.Format("function (s, e) {{ OnValueChanged(s, '{0}', '{1}', '{2}'); }}", c.Column.FieldName, c.KeyValue, Url.Action("UpdateProfileValue", "ManageAccess", null)); }).BindList(ViewBag.WeeKlyPlan) .Bind(DataBinder.Eval(c.DataItem, "WeeklyPlanID")).Render(); }); }); settings.Columns.Add(column => { column.Caption=Bixi_Atlas_Client_MVC_TicketPortal_MA_Localization.resDateFrom; column.FieldName = "FromDate"; column.SetDataItemTemplateContent(c => { Html.DevExpress().DateEdit(dSettings => { dSettings.Name = "datefrom" + c.KeyValue; dSettings.Width = System.Web.UI.WebControls.Unit.Percentage(100); dSettings.Properties.ClientSideEvents.ValueChanged = String.Format("function (s, e) {{ OnValueChanged(s, '{0}', '{1}', '{2}'); }}", c.Column.FieldName, c.KeyValue, Url.Action("UpdateProfileValue", "ManageAccess", null)); }).Bind(DataBinder.Eval(c.DataItem, c.Column.FieldName)).Render(); }); }); settings.Columns.Add(column => { column.Caption=Bixi_Atlas_Client_MVC_TicketPortal_MA_Localization.resDateTo; column.FieldName = "ToDate"; column.SetDataItemTemplateContent(c => { Html.DevExpress().DateEdit(dSettings => { dSettings.Name = "dateto" + c.KeyValue; dSettings.Width = System.Web.UI.WebControls.Unit.Percentage(100); dSettings.Properties.ClientSideEvents.ValueChanged = String.Format("function (s, e) {{ OnValueChanged(s, '{0}', '{1}', '{2}'); }}", c.Column.FieldName, c.KeyValue, Url.Action("UpdateProfileValue", "ManageAccess", null)); }).Bind(DataBinder.Eval(c.DataItem, c.Column.FieldName)).Render(); }); }); settings.Columns.Add(column => { column.Caption=Bixi_Atlas_Client_MVC_TicketPortal_MA_Localization.resRemarks; column.FieldName = "Remarks"; column.SetDataItemTemplateContent(c => { Html.DevExpress().TextBox(dSettings => { dSettings.Name = "Remarks" + c.KeyValue; dSettings.Width = System.Web.UI.WebControls.Unit.Percentage(100); var prop = (TextEditProperties)column.PropertiesEdit; prop.ValidationSettings.RequiredField.IsRequired = true; prop.ValidationSettings.RequiredField.ErrorText = "Please Enter Value"; prop.ValidationSettings.ValidateOnLeave = true; dSettings.Properties.ClientSideEvents.ValueChanged = String.Format("function (s, e) {{ OnValueChanged(s, '{0}', '{1}', '{2}'); }}", c.Column.FieldName, c.KeyValue, Url.Action("UpdateProfileValue", "ManageAccess", null)); }).Bind(DataBinder.Eval(c.DataItem, c.Column.FieldName)).Render(); }); }); settings.KeyFieldName = "ProfileZoneID"; settings.Settings.VerticalScrollBarStyle = GridViewVerticalScrollBarStyle.Standard; settings.Settings.VerticalScrollBarMode = ScrollBarMode.Auto; settings.SettingsPager.Visible = false; settings.SettingsPager.Mode = GridViewPagerMode.ShowAllRecords; settings.SettingsBehavior.AllowSelectSingleRowOnly = true; settings.SettingsBehavior.AllowSelectByRowClick = true; settings.SettingsBehavior.AllowSort = false; settings.HtmlRowPrepared = (sender, e) => { if (e.RowType != GridViewRowType.Data) return; e.Row.CssClass = e.GetValue("ROW_STYLE").ToString(); }; }).Bind(Model.CurrentActor.Profiles).GetHtml()
Show previous comments (1)

    Hello can you provide the small sample for  that.

    Lanette (DevExpress Support) 11 years ago

      Hello,

      As Marion mentioned in the previous comment, it's difficult to provide you with a solution without detailed information about your requirements. Please describe your scenario and clarify the questions in the previous comment.
      We will do our best to help you.

        Requirement is as I attached screenshot if user enter empty remark or invalid date from and invalid date to (like date from should not be greater than date to) and when I press save button error will be displayed it should not be saved
        Regards
        Sunil

        Answers approved by DevExpress Support

        created 11 years ago

        Hello,
        I have created a sample project based on your requirements. Please see the attachment.
        It uses GridView 's BatchEdit mode and a custom attribute to validate the model's properties.

        To learn more about field validation and batch editing in GridView, please follow the "GridView - How to validate a model field based on another field's value " example and the "Batch Editing " demo.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.