Prevent rebind

2 posts, 1 answers
  1. Carl-Johan
    Carl-Johan avatar
    22 posts
    Member since:
    May 2008

    Posted 24 Oct 2008 Link to this post

    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

  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 24 Oct 2008 Link to this post

    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

  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top