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

Need a InLine Edit - OnUpdateCommand Demo

5 Answers 182 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 21 Aug 2008, 03:27 PM

My Problem: The update command (and insert command) is not refreshing the grid.  I have a problem with both insert and update, but for this post lets just focus on update.

My Code:
I have a data grid (residing on a tab).  

I am using InLine Edit Mode, with no column templates.

When the user edits the row and later clicks the Update command, I execute my OnUpdateCommand() method.  In this method, I successfully pull the user inputs, execute the SQL updates. All is good.

The inline edit, goes away, but the user does not see the data grid reflect the update.

Now the user can hit the refresh data grid command, and that will work.

I then attempted to execute the same refresh command after the OnUpdateCommand had done it's work, but still no grid refresh.

Why I am Picking-On the OnUpdateCommand:

OnUpdateCommand="grdAltProductCodes_UpdateCommand" 

I went to the grid's mark up, removed the OnUpdateCommand attribute.  The result is that the user 

  • clicks edit
  • changes text box data
  • [I sneak over to the sql table and add/update 5 new records] 
  • clicks update command, [no sql update occurs cause we are not calling the OnUpdateCommand ]. 
  • the data grid refreshes and the user sees the 5 updates I did directly to the database.

So everything is fine, till I attempt to use the OnUpdateCommand.  Then no grid refresh.

So what does my OnUpdateCommand have to do, to force the data grid to refresh? 
Is there a good, simple demo available?  Everything I found was for the automatic updates.

Also, I did grabbed the latest code as of yesterday.

Thank You!

protected void grdAltProductCodes_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)  
{  
    AlternateProductCodeDC altProductCode = new AlternateProductCodeDC();  
 
    //The GridTableView will fill the values from all editable columns in the hash  
    GridEditableItem editedItem = e.Item as GridEditableItem;  
    Hashtable newValues = new Hashtable();  
    e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);  
 
    //Set Primary Key Stored as a Delimited Value within the Query String  
    string[] selectedRecord = Request.QueryString["i"].Split(',');  
    this._presenter.OnViewInitialized(Int32.Parse(selectedRecord[0]), selectedRecord[1], selectedRecord[2], selectedRecord[3], DateTime.Parse(selectedRecord[4]));  
    altProductCode.MasterCompanyId = Int32.Parse(selectedRecord[0]);  
    altProductCode.CountryCode = selectedRecord[1];  
    altProductCode.Jurisdiction = selectedRecord[2];  
    altProductCode.ProductCode = selectedRecord[3];  
 
    //Read user values              
    altProductCode.AlternateProductCode = Convert.ToString(newValues["Alternate_Product_Code"]);  
    altProductCode.EffectiveDate = Convert.ToDateTime(newValues["Effective_Date"]);  
    if (newValues["Obsolete_Date"] == null)  
    {  
        altProductCode.ObsoleteDate = null;  
    }  
    else 
    {  
        altProductCode.ObsoleteDate = Convert.ToDateTime(newValues["Obsolete_Date"]);  
    }  
 
    //Have the presenter update the database  
    _presenter.OnAlternateProductCodeUpdate(altProductCode);  
 
    //Somehow get the datagrid to refresh itself  
    //RefreshGrid();  
    //e.Canceled = false;  



 

5 Answers, 1 is accepted

Sort by
0
Leon
Top achievements
Rank 1
answered on 21 Aug 2008, 07:37 PM
0
Jeff
Top achievements
Rank 1
answered on 22 Aug 2008, 10:29 AM
Thank you for the response. The demos were good to look at, but I haven't resolved my issue.  Is there more detail about the events that are fired when we use the OnCommands?

I did start looking at the OnNeedDataSource, which is something I currently do not have supplied.  I did go back and supply it, but the radGrid never called it.  I put a break point in the code, and it never hit that method.  So I have since removed it again.

The other tid-bit is when I edit the 2nd item, the grid does refresh and will finally show the results of the 1st edit.  So there is a refresh being triggered when I go into edit mode.  Just no refresh when I'm done with OnCommand, and a ReBind() doesn't trigger it either.

The only other item is this other post.  However, it stated that this bug "should" be fixed in the next release.
http://www.telerik.com/community/forums/thread/b311D-bcekdm.aspx

0
Sebastian
Telerik team
answered on 25 Aug 2008, 08:51 AM
Hi Tim,

Some operations like grouping/filtering/data editing with custom edit forms require advanced binding for RadGrid using the NeedDataSource event. This event will be raised automatically under the following circumstances. Further information about the event lifecycle of the control in most common scenarios you can find here

Hence I suggest you modify your implementation to move to NeedDataSource binding and utilize the update/insert logic presented in the online demos pointed by Leon.

Best regards,
Stephen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jeff
Top achievements
Rank 1
answered on 26 Aug 2008, 03:19 PM
I have an update to share.  Perhaps someone can elaborate on the behavior.

So I have this grid that was not refreshing when the user completes and edit/delete/insert as I was using the OnUpdateCommand/ OnDeleteCommand/ OnInsertCommand. 

I was getting into these methods, executing the SQL updates, but the grid never reloaded.  Oh and if I just omited the Command events ( doing just a showy edit ), the grid would refresh.  So use a Command Event, no refresh... I couldn't even force one.

I've been playing with the OnDataSourceNeeded.  Since I was loading the datagrid on pageload.  What I found is that OnDataSourceNeeded, was never called by my datagrid.


  {  
     DataTable data = _obj.GetDataTable();  
     grdAltProductCodes.DataSource = data;  
  }  


I ended up removing code above where I loaded the datagrid myself, and instead just let the magic happen. 

Thanks for the help.  I ended up taking one of those demo's and comparing line by line with datagrid.
0
Jeff
Top achievements
Rank 1
answered on 26 Aug 2008, 07:39 PM
Additionally, it was even easier to keep what I had.  I then went into each of the OnCommand (Edit,Update,Delete) and wipe out the data gird data source.

grid.DataSource = null

This resulted in the data grid requesting the OnNeedDataSource, and triggering the refresh.
Tags
Grid
Asked by
Jeff
Top achievements
Rank 1
Answers by
Leon
Top achievements
Rank 1
Jeff
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or