Telerik RadGrid loses values after PostBack

6 posts, 0 answers
  1. Bruno
    Bruno avatar
    11 posts
    Member since:
    Oct 2013

    Posted 15 Jan 2014 Link to this post

    Hello, I have a RadGrid with multiples textboxes to be edited.
    When i made "submit" (Postback on page) i lose all values inserted on that textboxes because RadGrid loses is values.

    How can i solve this problem?

    Any solution?
    Thanks, Bruno F.
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 16 Jan 2014 Link to this post


    Please use Advanced Data Binding (using the NeedDataSource event)  to bind the data in grid.

    You lost the because of before execute the InsertCommand/UpdateCommand event grid is already rebind the its data. Means : Radgrid1.DataSource = ""; RadGrid.DataBind(); code is executed before it reach to the InsertCommnad/UpdateCommand event.

    Jayesh Goyani
  3. Bruno
    Bruno avatar
    11 posts
    Member since:
    Oct 2013

    Posted 16 Jan 2014 Link to this post

    Jayesh GoyaniThanks Jayesh but, i don't wanna reload the data again (get data from database), I want to get the values of the textboxes that i change.

    Is that possible NeedDataSource?

    Because what i understant is that NeedDataSource will get the data again for database for example and i don't wanna that, i want get the values that i inserted in textboxes placed on grid.

    Any solution?
  4. Viktor Tachev
    Viktor Tachev avatar
    1790 posts

    Posted 21 Jan 2014 Link to this post

    Hello Bruno,

    In order to save the values entered in an EditForm you could different approached depending on your scenario.

    If you have DataSource for RadGrid that supports automatic operations you could update the values automatically. This method is illustrated in a documentation article here. Also a live example is available in this online demo.

    If the data source does not support automatic operations you would need to manually perform the update. You could use handler for RadGrid's UpdateCommand event in order to update the values. Additional information on manual CRUD operations is available in this article and also in an online demo here.

    Viktor Tachev
    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.
  5. JJ
    JJ avatar
    21 posts
    Member since:
    Jul 2014

    Posted 24 Jul 2014 Link to this post


    I build my Rad Grid dynamically:

     1. create columns in my user-control OnInit event
     2. create controls of the columns in the OnItemCreated event
     3. bind the data in the OnItemDataBound event
     4. set the RadGrid data-source property in the OnNeedDataSource event
     5. parent page uses Ajax update panel settings and add the User Control dynamically with load each time in its OnInit event..
     6. do not want to use EditForm or Batch mode just dynamically controls in columns in radGrid and save

    All is running smooth, but I loos my values after PostBack when I click on my save button and/or the RadGrid Save button. 

    I add the OnUpdateCommand event and AllowAutomaticUpdates="true" <not firing the event>

    what am I missing?
  6. JJ
    JJ avatar
    21 posts
    Member since:
    Jul 2014

    Posted 25 Jul 2014 Link to this post

    thanks mannn


    do not have to use ItemCreate nor ItemBound events...

    1. Parent Page with Ajax Settings (Rad Grid Light Binding) 
       a. use Load Event and onChange events of controls to determine diffrent scenarious of child controls 
       b. Build User Control each time on its OnInit Event
    2. Child User Control (Advance Binding - OnNeedDataSource)
       a. use OnInit Event to create the columns (to deep copy from the temp GridTemplateColumn in
       b. use RadAjaxManagerProxy
                c. OnInit Event (build columns)
                i.   Columns must use ItemTemplate and EditTemplage in the temp GridTemplateColumn with Binding Text='<%# Bind("TimeInterval") %>' 
                ii.  Add all the diffrent controls like checkbox, radnumericbox, radtextbox, datetimepickers, combobox...
                iii. Controls must use events:
                - OnInit 
                * (set Unique Id's, but Id's must be stored in server object or session variable, becuase it must be the same on each init create)
                * (set the visibility of the Control you want to use to true and the other to false, thus if this is the dataType and control to use set the visibility to true else false
                - OnDataBinding 
                * (bind to server object with correct dataField, can get dataField from GridTemplateColumn)
                - OnPreRender 
                * (set the column and row selectable, this is important if you want to make RadGrid like Excell data input and use the EditTemplate, this is very important for saving of data)
                       - OnTextChange (validation with Session variables)
                - EditItemTemplate contains OnInit and OnTextChange events
                - ItemTemplate contains OnInit and OnDataBinding events and OnPreRender
Back to Top