This is a migrated thread and some comments may be shown as answers.

cell values validation

7 Answers 96 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Allen
Top achievements
Rank 1
Allen asked on 13 Sep 2013, 07:53 PM
Please tell me how to validate the cell values.  If the two values are the same, error it out and do not update them.  Please refer to the PNG.

7 Answers, 1 is accepted

Sort by
0
Allen
Top achievements
Rank 1
answered on 18 Sep 2013, 01:37 PM
Can any one help?
0
Angel Petrov
Telerik team
answered on 18 Sep 2013, 03:39 PM
Hello Allen,

One possible realization is to subscribe to the OnBatchEditCellValueChanging client event and check the value in the other cell. If it is equal to the newly entered one you can alert the user and cancel the event. When following this approach the user will be prevented from entering a duplicate value.

Regards,
Angel Petrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Allen
Top achievements
Rank 1
answered on 19 Sep 2013, 07:39 PM
Can you give me a sample?  I have check the online documentation, but can't find any.
0
Allen
Top achievements
Rank 1
answered on 21 Sep 2013, 07:29 PM
Can anyone give me example for both client side and server side?  I really can't find any from the documentation.  Thanks
0
Angel Petrov
Telerik team
answered on 24 Sep 2013, 01:14 PM
Hello Allen,

Since the EditMode is set to Batch I would recommend using only a client-side solution. If the controls in the edit item cause a postback the changes made by the user will be lost.

Now to the solution of the problem. As I started in my previous post the correct approach would be to cancel the BatchEditCellValueChanging according to the value in the other cell. According to the version used in the real application the related cell value can be obtained in two ways:
  1. With the Q2 2013 service-pack version - using the BatchEditGetCellValue and obtaining a reference to the other cell.
  2. With the latest internal build you can directly obtain a reference to the related cell in the event handler as there are additional arguments exposed.

Please find in attachments the two fully runnable website which demonstrate the mentioned approaches. Note that we are always improving the Batch edit mode and the internal build provides a richer functionality than the service-pack(keyboard navigation, additional events are exposed and so on). The mentioned features will be included in the upcoming Beta release.


Regards,
Angel Petrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Allen
Top achievements
Rank 1
answered on 30 Sep 2013, 07:07 PM
Thank you for your help.  It works great.  However, for some other reason, I have changed the BatchEdit to editForm TextBox.  It no longer work.  For the same senerio, can you give me an example?  Please refer to the PNG file.
0
Angel Petrov
Telerik team
answered on 03 Oct 2013, 02:21 PM
Hi Allen,

One possible solution is to subscribe to the OnUpdateCommand event of the grid and cancel it if the text in the editors is the same:
protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
    {
        GridEditableItem editItem = e.Item as GridEditableItem;
        TextBox textBox1 = editItem["Column1UniqueName"].Controls[0] as TextBox;
        TextBox textBox2 = editItem["Column2UniqueName"].Controls[0] as TextBox;
        if (textBox1.Text == textBox2.Text)
        {
            e.Canceled = true;
        }
    }

Another solution would be to subscribe to the OnCommand client event of the grid and cancel the update:

ASPX:
<ClientSettings>
                <ClientEvents OnCommand="OnGridCommand" />
            </ClientSettings>

JavaScript:
function OnGridCommand(sender,args) {
            if (args.get_commandName() == "Update") {
                //check the editor values
                args.set_cancel(true)
            }
        }


Regards,
Angel Petrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Allen
Top achievements
Rank 1
Answers by
Allen
Top achievements
Rank 1
Angel Petrov
Telerik team
Share this question
or