Skip to content

Pass an editor's value to the server in batch edit mode, validate the value based on a condition, and pass the validation result to the client.

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/asp-net-web-forms-grid-validate-cell-values-on-server-in-batch-mode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grid View for ASP.NET Web Forms - How to validate entered cell values on the server in batch edit mode

This example demonstrates how to pass an editor's value to the server in batch edit mode, validate the value based on a condition, and pass the validation result to the client.

Invalid cell values in batch mode

Overview

Create the Grid View control and add a callback control to the page. For particular grid columns, specify their edit settings and handle client-side TextChanged events. In the handler, get an editor's value and call the callback's PerformCallback method to pass the value to the server.

var editor;
function OnTextChanged(s, e) {
    editor = s;
    clb.PerformCallback(fieldName + '|' + s.GetText());
    // ...
}
<dx:ASPxGridView ID="Grid" ClientInstanceName="grid" runat="server" KeyFieldName="ID" ... >
    <Columns>
        <!-- ... -->
        <dx:GridViewDataTextColumn FieldName="C3">
            <PropertiesTextEdit>
                <ClientSideEvents TextChanged="OnTextChanged" KeyDown="OnKeyDown" />
                <!-- ... -->
            </PropertiesTextEdit>
        </dx:GridViewDataTextColumn>
        <!-- ... -->
    </Columns>
    <SettingsEditing Mode="Batch" />
</dx:ASPxGridView>
<dx:ASPxCallback ID="ASPxCallback1" runat="server" ClientInstanceName="clb" OnCallback="ASPxCallback1_Callback">
    <ClientSideEvents CallbackComplete="OnCallbackComplete" />
</dx:ASPxCallback>

Handle the callback's server-side Callback event. In the handler, specify error text strings for invalid cells based on a condition and save these text strings to the e.Result argument property. Then pass the result to the callback's client-side CallbackComplete event to complete validation on the client.

var isError = false;
function OnCallbackComplete(s, e) {
    // ...
    if (e.result != null) {
        grid.batchEditApi.StartEdit(currentIndex, grid.GetColumnByField(fieldName).index);
        editor.SetIsValid(false);
        editor.SetErrorText(e.result);
        isError = true;
    }
    else
        isError = false;
}
protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e) {
    string[] parameters = e.Parameter.Split('|');
    switch (parameters[0]) {
        case "C3":
            if (parameters[1] == "AAA")
                e.Result = string.Format("'{0}' is invalid value", parameters[1]);
            break;
        case "C5":
            if (parameters[1] == "BBB")
                e.Result = string.Format("'{0}' is invalid value", parameters[1]);
            break;             
        default:
            break;
    }
    // ...
}

Files to Review

Documentation

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

Pass an editor's value to the server in batch edit mode, validate the value based on a condition, and pass the validation result to the client.

Topics

Resources

License

Stars

Watchers

Forks