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

[Solved] RadGrid XXX_ItemCommand(object source, GridCommandEventArgs e) help question

1 Answer 95 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lee
Top achievements
Rank 1
Lee asked on 02 May 2013, 03:27 PM
I have question that I have not been able to figure out, I have grid that displays records and also the "Add new record" button & buttonLink. when the grid is in edit mode and the elements for the new record are displayed I have a drop down with values and some static text fields and a dynamic text field that is displayed if a specific value in the drop down is chosen. the dynamic text field also has an  ASP RequiredFieldValidator

in the grid_ItemCommand()  method I would like to do some additional validation and make the dynamic text field and it's vaidator appear, and the edit screen stay active with it's current values in place.

I'm new to RadGrid and not sure how to properly leave the grid in edit mode and have all the fields appear that I would Like and the associated data too. here is the snippet of code that have just trying to get the dynamic text field and the validator to appear

specCert = value from the dropdown
specOther = value from the dynamic text field that should have appeared and required being populated.
txtSpecOther = id of the dynamic text field
rfvOther = id of the RequiredFieldValidator

                        if ((specCert.Equals("370")) && (String.IsNullOrEmpty(specOther)))
                        {
                            
                            //Get the currently open item's entries and assign them to the Add New Record form's fields
                            GridEditableItem insertedItem = e.Item.OwnerTableView.GetInsertItem();
                            String ucID = GridEditFormItem.EditFormUserControlID;
                            UserControl i_uc = insertedItem.FindControl(ucID) as UserControl;

                            ((TextBox)i_uc.FindControl("txtSpecOther")).Visible = true;
                            ((RequiredFieldValidator)i_uc.FindControl("rfvOther")).Visible = true;
                            
                            // show the validation error message
                            ((RequiredFieldValidator)i_uc.FindControl("rfvOther")).IsValid = false;

                            return;
                        }
                        //other code that I dont want to run
                        ......
                        ......
                        ......
                        ......
                        //other code that I dont want to run

thank you for any help I can get.

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 07 May 2013, 08:39 AM
Hello,

In order to achieve your goal you could set the Canceled property of the event argument object of the ItemCommand event. This property will cancel the current operation from executing and thus allow you to modify the settings you need.

Give it a try and you should succeed.

Kind regards,
Andrey
the Telerik team
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 their blog feed now.
Tags
Grid
Asked by
Lee
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or