RadGrid control does not fire Update event

Posted by Community Admin on 04-Aug-2018 15:55

RadGrid control does not fire Update event

All Replies

Posted by Community Admin on 30-Sep-2013 00:00

I am using a RadGrid control on a custom widget page.  I can successfully bind data to a Dynamic Module, but the UpdateCommand event does not fire and am unable to update any changes made to
the grid after edit.  I have enabled ViewState and RadScriptManager for the page hosting the widget.  EditCommand fires, but not UpdateCommand.   Any suggestions?


1.      Create new custom wizard using Thunder.

2.      Add RadGrid control to ascx page.

3.      Data bind control during InitializeControls

4.      Registered events for RadGrid control 

5.      The EditCommand control will fire, but not the RadGrid1_UpdateCommand  

6.      The page where the widget has been added has ViewState and RadScriptManager checked.


<telerik:radgrid id="RadGrid1" runat="server" Skin="Black" >
    <ClientSettings>
        <Scrolling AllowScroll="True" UseStaticHeaders="True" />
    </ClientSettings>
    <mastertableview EditMode="InPlace" CommandItemDisplay="TopAndBottom" AutoGenerateColumns="False" DataKeyNames="ID" AllowAutomaticInserts="true">
 
        <EditFormSettings InsertCaption="Add new item" CaptionFormatString="Edit Item: 0" CaptionDataField="ID" PopUpSettings-Modal="true" />
    <Columns>
     
     <telerik:GridBoundColumn HeaderText="Title" DataField="Title" UniqueName="Title"></telerik:GridBoundColumn>
        <telerik:GridBoundColumn HeaderText="Location" DataField="Location" UniqueName="Location"></telerik:GridBoundColumn>
 
     <telerik:GridEditCommandColumn HeaderText="Edit" UniqueName="EditCommandColumn"></telerik:GridEditCommandColumn>
     <telerik:GridButtonColumn CommandName="Delete" Text="Delete" HeaderText="Delete" UniqueName= "DeleteColumn" />
    </Columns>
  
 
<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column"></RowIndicatorColumn>
 
 
<PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
</mastertableview>
 
<PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
 
<FilterMenu EnableImageSprites="False"></FilterMenu>
     </telerik:radgrid>

Init Controls 

protected override void InitializeControls(GenericContainer container)
      
   
 
          RadGrid Grid = this.Container.GetControl<RadGrid>("RadGrid1", true);
 
          Grid.UpdateCommand += new GridCommandEventHandler(RadGrid1_UpdateCommand);
          Grid.NeedDataSource += new GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource);
          Grid.UpdateCommand += new GridCommandEventHandler(RadGrid1_UpdateCommand);
          Grid.DeleteCommand += new GridCommandEventHandler(RadGrid1_DeleteCommand);
          Grid.EditCommand += new GridCommandEventHandler(RadGrid1_EditCommand);
           
 
          // Fetch a collection of "live" and "visible" project items.
          var myCollection = GetDataItems();
 
          // Binds the collection of Person items to the RadGrid
          Grid.DataSource = myCollection;
          Grid.DataBind();
      
 
      


 UpdateCommand 

protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e)
        
            //Get the GridEditableItem of the RadGrid    
            GridEditableItem editedItem = e.Item as GridEditableItem;
            //Get the primary key value using the DataKeyValue.    
            Guid projectID = (Guid)editedItem.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"];
            //Access the textbox from the edit form template and store the values in string variables.    
 
 
            Hashtable newValues = new Hashtable();
            e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
 
 
            // Set the provider name for the DynamicModuleManager here. All available providers are listed in
            // Administration -> Settings -> Advanced -> DynamicModules -> Providers
            var providerName = String.Empty;
            DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
            Type projectType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.BugTracking.Project");
          
            try
            
 
                // This is how we get the project item by ID
                DynamicContent projectItem = dynamicModuleManager.GetDataItem(projectType, projectID);
 
                // This is how values for the properties are set
                projectItem.SetValue("Title", newValues["Title"]);
                projectItem.SetValue("Description", newValues["Description"]);
                projectItem.SetValue("PublicationDate", DateTime.Now);
 
                // You need to call SaveChanges() in order for the items to be actually persisted to data store
                dynamicModuleManager.SaveChanges();
 
            
            catch (Exception ex)
            
              
            
 
        


Get Collection 

// Gets a collection of "live" and "visible" project items.
      public IQueryable<DynamicContent> GetDataItems()
      
          DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
          Type projectType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.BugTracking.Project");
  
          // Fetch a collection of "live" and "visible" project items.
          var myCollection = dynamicModuleManager.GetDataItems(projectType)
              .Where(i => i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live && i.Visible == true);
  
          return myCollection;
      

I based my code on the following example:

www.sitefinity.com/.../insert_update_delete_content_items_with_radgrid_for_asp_net_ajax

Posted by Community Admin on 03-Oct-2013 00:00

Hi Michael,

The blog post which you are using for reference is a bit old and it is suitable for 3.x projects.  My suggestion is to check the following forum threads where you can find some information which could be useful for you.

RadGrid control add, edit, refresh and delete. Works on a page, but not on a backend page?

Radgrid export in Custom Control

Regards,
Kaloyan
Telerik

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed