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

[Solved] OnDeleteCommond and the ObjectDataSource

1 Answer 99 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sean
Top achievements
Rank 1
Sean asked on 20 Apr 2009, 06:27 PM
I finally after much irritation got the insert to work. Im new to the objectdatasource AND the rad controls.

I can't seem to get my datakey to show up as a parameter in my delete method...The delete is being called but the parameter is null. If you have any ideas about how to get the update to work that would be helpful also.

  <asp:objectdatasource ID="objdsRoles" runat="server"  
      selectmethod="GetAllRoles"  
      deletemethod="DeleteRole" 
      insertmethod="InsertRole" 
      oldvaluesparameterformatstring="original_{0}" 
      typename="MyNamespace.Data.Helpers"   
      > 
      <insertparameters> 
         <asp:controlparameter controlid="txtRoleName" type="String" name="RoleName" /> 
      </insertparameters> 
      <deleteparameters> 
         <asp:parameter name="Role"  type="String" /> 
      </deleteparameters> 
</asp:objectdatasource> 
 
 <telerik:radgrid id="rgRoles" runat="server"  
      mastertableview-editmode="InPlace"  
      allowautomaticupdates="True"  
      datasourceid="objdsRoles"  
      gridlines="None"  
      autogenerateeditcolumn="True" 
      autogeneratedeletecolumn="true"  
      ondeletecommand="rgRoles_OnDeleteCommand"
      <headercontextmenu enabletheming="True"
         <collapseanimation duration="200" type="OutQuint" /> 
      </headercontextmenu> 
      <mastertableview datakeynames="Role"
      </mastertableview> 
   </telerik:radgrid> 
 

//Code Behind stuffs.... 
void  rgRoles_OnDeleteCommand(object source, GridCommandEventArgs e) 
   { 
      objdsRoles.Delete(); 
   } 
 
//Code to delete the roll that is showing the null value 
 
public void DeleteRole( string Role ) 
      { 
         try 
         { 
            Roles.DeleteRole(Role, true); 
         } 
         catch( Exception ex ) 
         { 
            throw new Exception( "Failed to delete role.", ex ); 
         } 
      } 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 23 Apr 2009, 07:09 AM
Hi,

In order to perform  automatic operations you need to set the AllowAutomaticDeletes="True" ,AllowAutomaticInserts="True"  and AllowAutomaticUpdates="True" . I noticed you haven't done this for delete and insert.

You can also check out the following code library :

http://www.telerik.com/community/code-library/aspnet-ajax/grid/automatic-operations-with-objectdatasource-control.aspx

Thanks,
Princy




Tags
Grid
Asked by
Sean
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or