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

Prevent rebind

1 Answer 41 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Carl-Johan
Top achievements
Rank 1
Carl-Johan asked on 24 Oct 2008, 07:07 AM

When I update my grid I look for Exceptions. If I find an exception the grid remains in edit mode. The problem is that when the Exception gets thrown, I handle it and the grid rebinds.

 

The textboxes then gets the original value.

 

So if the textbox have the text “Example text” and the user try to update the record with an empty string, an Exception gets thrown. Then the textbox once again has the text “Example text”.

 

So how do I prevent this? I would like to have the textbox showing the value the user put there.

Thanks

Kalle

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 24 Oct 2008, 10:09 AM
Hi,

Try resetting the values of the controls in the edit form as shown below when the grid rebinds after handling the exception.

CS:
   protected void RadGrid1_ItemUpdated(object source, Telerik.Web.UI.GridUpdatedEventArgs e) 
        { 
            if (e.Exception != null) 
            { 
                e.KeepInEditMode = true
                e.ExceptionHandled = true
                string[] list = new string[2]; 
                GridEditableItem editedItem = (GridEditableItem)e.Item; 
                list[0] = ((System.Web.UI.WebControls.TextBox)(editedItem["CompanyName"].Controls[0])).Text; 
                list[1] = ((System.Web.UI.WebControls.TextBox)(editedItem["ContactName"].Controls[0])).Text; 
                Session["List"] = list; 
              
                 
            }  
             
        } 
 
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if(e.Item is GridEditableItem && e.Item.IsInEditMode) 
            { 
                GridEditableItem editedItem = (GridEditableItem)e.Item; 
                if( Session["List"]!=null) 
                { 
                    string[] list=(string[]) Session["List"]; 
               ((System.Web.UI.WebControls.TextBox)(editedItem["CompanyName"].Controls[0])).Text = list[0].ToString(); 
                    ((System.Web.UI.WebControls.TextBox)(editedItem["ContactName"].Controls[0])).Text = list[1].ToString(); 
                    
                } 
                Session["List"] = null; 
            } 
                
        } 

Thanks,
Princy

Tags
Grid
Asked by
Carl-Johan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or