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

[Solved] Error Detection in Grid Edit Form

1 Answer 111 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chuck Lawson
Top achievements
Rank 1
Chuck Lawson asked on 06 May 2013, 03:30 PM
I am attempting to do a compare of values from three dropdowns in a grid edit form:
If the selected value from any of the dropdowns matches the dropdown from any other dropdown then I would like to be able to stop the update somehow.
This posts the message but I am not sure how to stop the update.
 
Here is the item created:
protected void gvEdit_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
   {
       if (e.Item is GridEditableItem && e.Item.IsInEditMode)
       {
           DropDownList list1 = (e.Item as GridEditableItem)["GridDropDownColumn999111"].Controls[0] as DropDownList;
           list1.AutoPostBack = true;
           list1.SelectedIndexChanged += new System.EventHandler(this.list1_SelectedIndexChanged);
 
           DropDownList list2 = (e.Item as GridEditableItem)["GridDropDownColumn9992"].Controls[0] as DropDownList;
           list2.AutoPostBack = true;
           list2.SelectedIndexChanged += new System.EventHandler(this.list2_SelectedIndexChanged);
 
           DropDownList list3 = (e.Item as GridEditableItem)["GridDropDownColumn9993"].Controls[0] as DropDownList;
           list3.AutoPostBack = true;
           list3.SelectedIndexChanged += new System.EventHandler(this.list3_SelectedIndexChanged);
       }
   }

Here is the index changed:
protected void list1_SelectedIndexChanged(object sender, System.EventArgs e)
    {
        String x = "System 1, System 2, and System 3 must have different values";
        DisplayMessage(y);
     
    }
   protected void list2_SelectedIndexChanged(object sender, System.EventArgs e)
   {
       String x = "System 1, System 2, and System 3 must have different values";
       DisplayMessage(x);
 
   }
   protected void list3_SelectedIndexChanged(object sender, System.EventArgs e)
   {
       String x = "System 1, System 2, and System 3 must have different values";
       DisplayMessage(x);
 
   }

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 07 May 2013, 08:33 AM
Hello,

1. server side
protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
   {
       GridEditableItem item = e.Item as GridEditableItem;
       // compare your dropdownlis value if it is same then
       e.Canceled = true; // cancel the update command event
 
 
   }

2. client side
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            DropDownList list1 = (e.Item as GridEditableItem)["GridDropDownColumn999111"].Controls[0] as DropDownList;
            DropDownList list2 = (e.Item as GridEditableItem)["GridDropDownColumn9992"].Controls[0] as DropDownList;
            DropDownList list3 = (e.Item as GridEditableItem)["GridDropDownColumn9993"].Controls[0] as DropDownList;
 
            CompareValidator cw = new CompareValidator();
            cw.ID = "cv" + DateTime.Now.Ticks;
            cw.ControlToCompare = list1.ID;
            cw.ControlToValidate = list1.ID;
            cw.Operator = ValidationCompareOperator.NotEqual;
        }
    }


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Chuck Lawson
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or