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

RadGrid Insert Signature

7 Answers 115 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David Kingston
Top achievements
Rank 2
David Kingston asked on 01 Oct 2008, 06:44 PM
I have a RadGrid hooked up to an ObjectDataSource, and it's Ajax enabled.

The update and delete functions work fine.  The insert function returns an error saying that it can't find a generic method that takes the parameters DivisionName, DivisionDescription, DivisionID.

I don't get it, Division ID visible is set to false.  The signature for insert is just DivisionName and Divsion Description.  Why is it trying to add DivisionID to the equation?

onitemcreated only does validation just like the example, and that works.

The ASPX looks like this:

<telerik:RadGrid ID="RadGrid1" runat="server"
    AllowPaging="True"
    AllowSorting="True"
    DataSourceID="CmdbDivision"
    GridLines="None"
    Skin="Office2007"
    AllowAutomaticInserts="True"
    AllowAutomaticUpdates="True"
    AllowAutomaticDeletes="True"
    Width="99%"
    onitemcreated="RadGrid1_ItemCreated"
    AutoGenerateColumns="False">
<MasterTableView DataSourceID="CmdbDivision"
            OverrideDataSourceControlSorting="true"
            CommandItemDisplay="Top"
            EditMode="InPlace"
            DataKeyNames="DivisionID">
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>

<ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
    <Columns>
        <telerik:GridEditCommandColumn>
        </telerik:GridEditCommandColumn>
        <telerik:GridBoundColumn DataField="DivisionID"
            HeaderText="DivisionID" SortExpression="DivisionID"
            UniqueName="DivisionID" DataType="System.Int32" Visible="False">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="DivisionName" HeaderText="DivisionName"
            SortExpression="DivisionName" UniqueName="DivisionName">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="DivisionDescription"
            HeaderText="DivisionDescription" SortExpression="DivisionDescription"
            UniqueName="DivisionDescription">
        </telerik:GridBoundColumn>
        <telerik:GridButtonColumn CommandName="Delete" Text="Delete"
            UniqueName="column">
        </telerik:GridButtonColumn>
    </Columns>
<EditFormSettings>
<EditColumn UniqueName="EditCommandColumn1"></EditColumn>
</EditFormSettings>
    <PagerStyle Mode="NextPrevAndNumeric" />
</MasterTableView>
        <ClientSettings>
            <Scrolling AllowScroll="True" UseStaticHeaders="True" />
        </ClientSettings>
<FilterMenu EnableTheming="True">
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
</FilterMenu>
    </telerik:RadGrid>
<asp:ObjectDataSource ID="CmdbDivision" runat="server"
        DeleteMethod="Delete"
        InsertMethod="Insert"
        SelectMethod="FetchAll"
        TypeName="CMDB.TblDivisionController"
        UpdateMethod="Update">
        <DeleteParameters>
            <asp:Parameter Name="DivisionID" Type="Object" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="DivisionID" Type="Int32" />
            <asp:Parameter Name="DivisionName" Type="String" />
            <asp:Parameter Name="DivisionDescription" Type="String" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="DivisionName" Type="String" />
            <asp:Parameter Name="DivisionDescription" Type="String" />
        </InsertParameters>
    </asp:ObjectDataSource>



7 Answers, 1 is accepted

Sort by
0
David Kingston
Top achievements
Rank 2
answered on 01 Oct 2008, 08:34 PM
I had a sneaking suspicion that it is because DataKeyNames="DivisionID".  But that is not the case, and removing it makes the delete function not work anymore. 

Anyone have suggestions, or know where the documentation for the generated method signature is at?  Or some property that I'm missing?

I could have sworn that the insert was working before I got delete to work, but I can't find any combinations of settings that would make it work again.

0
Serrin
Top achievements
Rank 1
answered on 01 Oct 2008, 08:53 PM
Hey David,

Have you tried adding:

      <asp:Parameter Name="DivisionID" Type="Int32" />

into the InsertParameters?  My best guess (without having the datasource and all that goodness) is that since DataKeyNames="DivisonID" then you will need to have that in every parameter group (insert, update, delete) as that's the key it is using...  let me know if that works. 
0
David Kingston
Top achievements
Rank 2
answered on 01 Oct 2008, 09:23 PM
Nope.  I thought of that as well.  The method signature of my DAL for an insert is just DivisionName and DivisionDescription.  I also looked through the ObjectDataSource settings for insert, and can't find a method that includes the DivisionID as a signature.  My DAL was generated by SubSonic.  The table only contains an ID, Name, Description -- basic lookup table.

I thought the update button just wired the necessary columns to the parameters in the ObjectDataSource.  Why is it adding paramters not defined by the ObjectDataSource?

An interesting thing happens in the error message, though.  If you add DivisionID to the insert parameters above Name and Description, the exception lists the columns in a different order:
InvalidOperationException: ObjectDataSource 'CmdbDivision' could not find a non-generic method 'Insert' that has parameters: DivisionID, DivisionName, DivisionDescription.

Before the exception message had DivisionID at the end of the equation.  Like it looped through the parameters in the list and then added DivisionID at the end.

I also messed around with visible, display, and read only for the ID column to no avail.

I guess I can try to add a custom form template, or just wire up the insert event and write my own insert commands -- seems like I should be able to do this without any code though.  I mean who writes an insert statement that takes an ID that is autogenerated by the db?
0
Scott Hansen
Top achievements
Rank 1
answered on 31 Oct 2008, 03:27 AM
Any resolution on this - having same problem.

Thanks
0
Nikolay Rusev
Telerik team
answered on 31 Oct 2008, 08:01 AM
Hello ,

On the links below you will find information about ObjectDataSource and how RadGrid is using any data source control:
ObjectDataSource Class
Automatic DataSource operations

Regarding the issue which David has: GridBoundColumn with DataField DivisionID must be marked as ReadOnly=true instead. This will resolve the problem.

Attached to this forum post you will find a sample project which illustrates another possible way to bind RadGrid via ObjectDataSource without need to specify any parameter for select/update/insert/delete.

Kind regards,
Nikolay
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
David Kingston
Top achievements
Rank 2
answered on 31 Oct 2008, 01:48 PM
I haven't tested this yet, but will try your suggestions later this afternoon.

I also noticed that when you have SubSonic autogenerate the DAL for you that you need to refresh the files in Visual Studio to get new and updated signatures.  I don't know if this was a problem for me or not.

In the mean time, I just made a Edit/Insert Template and caught the CommandItem from the save/insert button just like the online example for custom edit forms.  The custom form was a good idea, as I was able to add audit items that I wanted to include in the form down the road.

I'd still like the auto edit/delete stuff to work.  I'll try your examples later this afternoon and post back here what I found.
0
Nikolay Rusev
Telerik team
answered on 03 Nov 2008, 03:26 PM
Hello David,

If you don't need to change methods signature you can set ReadOnly=true for DivisionID column.
Thus the value of this column won't be required.

I hope the provided information so far is helpful.

Sincerely yours,
Nikolay
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
David Kingston
Top achievements
Rank 2
Answers by
David Kingston
Top achievements
Rank 2
Serrin
Top achievements
Rank 1
Scott Hansen
Top achievements
Rank 1
Nikolay Rusev
Telerik team
Share this question
or