DataSource Inserting event not firing

4 posts, 1 answers
  1. Phil
    Phil avatar
    273 posts
    Member since:
    Jul 2008

    Posted 31 Dec 2008 Link to this post

    Hi, and Happy New years:
    I have a RADGrid (Nov 2008 ver) control and I am attempting to inserts and update the 'detail' table.  It does not automatically fire the 

    ObjectDataSource_Inserting right after the RadGrid_InsertCommand event.  Any ideas?  Is their a boolean flag I should or could check?

     

  2. Phil
    Phil avatar
    273 posts
    Member since:
    Jul 2008

    Posted 02 Jan 2009 Link to this post

    Additional info, ... I have done this before, but using C# and this is in VB.Net.  Slight differences, ... I took out the handling and used the OnInserting attribute in the datasource but not change.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Answer
    Kevin Babcock
    Kevin Babcock avatar
    189 posts
    Member since:
    Mar 2007

    Posted 02 Jan 2009 Link to this post

    Hi Phil,

    I tried to reproduce your problem but was unsuccessful. I was able to successfully handle both the RadGrid's InsertCommand and the ObjectDataSource's ItemInserting command. Here is the code I used to test this:

    Default.aspx
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Telerik.Examples._Default" %> 
     
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     
    <html xmlns="http://www.w3.org/1999/xhtml" > 
    <head runat="server"
        <title>Example</title> 
    </head> 
    <body> 
        <form id="form1" runat="server"
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server" /> 
             
            <telerik:RadGrid ID="RadGrid1" runat="server" 
                AllowAutomaticInserts="True" 
                AutoGenerateColumns="False" 
                DataSourceID="ObjectDataSource1" 
                OnInsertCommand="RadGrid1_InsertCommand"
                <MasterTableView 
                    CommandItemDisplay="TopAndBottom" 
                    DataKeyNames="ID"
                    <Columns> 
                        <telerik:GridNumericColumn 
                            DataField="ID" 
                            HeaderText="ID">                         
                        </telerik:GridNumericColumn> 
                        <telerik:GridBoundColumn 
                            DataField="Value" 
                            HeaderText="Value"
                        </telerik:GridBoundColumn> 
                    </Columns> 
                </MasterTableView> 
            </telerik:RadGrid>       
                 
            <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"  
                DataObjectTypeName="Telerik.Examples.Item"  
                InsertMethod="Insert"  
                OnInserting="ObjectDataSource1_Inserting"  
                SelectMethod="Select"  
                TypeName="Telerik.Examples.ItemDataSource"
            </asp:ObjectDataSource>      
             
        </form> 
    </body> 
    </html> 
     

    Default.aspx.cs
    using System.Web.UI.WebControls; 
     
    namespace Telerik.Examples 
        public partial class _Default : System.Web.UI.Page 
        { 
            protected void RadGrid1_InsertCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) 
            { 
                // add additional logic here 
            } 
     
            protected void ObjectDataSource1_Inserting(object sender, ObjectDataSourceMethodEventArgs e) 
            { 
                // add additional logic here 
            } 
        } 
     

    ItemDataSource.cs
    using System.Collections.Generic; 
    using System.ComponentModel; 
     
    namespace Telerik.Examples 
        [DataObject] 
        public class ItemDataSource 
        { 
            [DataObjectMethod(DataObjectMethodType.Select, true)] 
            public IEnumerable<Item> Select() 
            { 
                var items = new Item[]{ 
                    new Item { ID=1, Value="Something" }, 
                    new Item { ID=2, Value="Something Else" } 
                }; 
                return items; 
            } 
     
            [DataObjectMethod(DataObjectMethodType.Insert, true)] 
            public void Insert(Item item) 
            { 
                // Add insert code here 
            } 
        } 
     
        public class Item 
        { 
            public int ID { getset; } 
            public string Value { getset; } 
        } 
     

    Perhaps this simple example will help you figure out what is going wrong with your application. If not, could you provide more details (and code samples) so that I can help you further?

    Thanks,
    Kevin Babcock
  5. Phil
    Phil avatar
    273 posts
    Member since:
    Jul 2008

    Posted 02 Jan 2009 Link to this post

    Oh drat ... AllowAutomaticInserts, I missed it, in my old sample code.  I have not been coding telerik for a number of months.
Back to Top