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

auto Update Not getting dataKey

1 Answer 143 Views
Grid
This is a migrated thread and some comments may be shown as answers.
kyle goodfriend
Top achievements
Rank 2
kyle goodfriend asked on 18 Jul 2010, 12:31 AM
I have a grid that I have to be missing something really simple, but after hours, I am asking for some help.  The code is attached.  If I edit a grid line and update, it doesn't save the results.  It appears if the save function is working because I can hard code the key in the table I am editing, and the results save.  If I remove it and add a ?, it won't save.  On the grid1_ItemUpdated event, if I place the following, the correct key comes back.  So, something is not getting passed to the datasource.  I am JUST working on the update.  I don't anticipate the delete or insert to function correctly.  I have a FormView to a datasource and it works fine.  Thanks!

Dim strID As String = e.Item.GetDataKeyValue("ID").ToString()
Response.Write(strID)

So the event has the correct key, but the datasource doesn't not get it.  Can somebody take a look for me and tell me what I am missing?
Grid:
    
     <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="AccessDataSource2"
        GridLines="None" AutoGenerateDeleteColumn="True"
        AutoGenerateEditColumn="True" AllowAutomaticDeletes="True"
        AllowAutomaticUpdates="True" AllowAutomaticInserts="True"
        AutoGenerateColumns="False" Width="690">
<MasterTableView DataKeyNames="ID" CommandItemDisplay="TopAndBottom"
            DataSourceID="AccessDataSource2" EditMode="EditForms">

<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>

<ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
    <Columns>
        <telerik:GridBoundColumn DataField="ID" DataType="System.Int32" HeaderText="ID"
            ReadOnly="True" SortExpression="ID" UniqueName="ID">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="Address" HeaderText="Address"
            SortExpression="Address" UniqueName="Address">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="FirstName" HeaderText="FirstName"
            SortExpression="FirstName" UniqueName="FirstName">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="LastName" HeaderText="LastName"
            SortExpression="LastName" UniqueName="LastName">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="Email" HeaderText="Email"
            SortExpression="Email" UniqueName="Email">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="Company" HeaderText="Company"
            SortExpression="Company" UniqueName="Company">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="JobFunction" HeaderText="JobFunction"
            SortExpression="JobFunction" UniqueName="JobFunction">
        </telerik:GridBoundColumn>
        <telerik:GridCheckBoxColumn DataField="Resident" DataType="System.Boolean"
            HeaderText="Resident" SortExpression="Resident" UniqueName="Resident">
        </telerik:GridCheckBoxColumn>
        <telerik:GridCheckBoxColumn DataField="Owner" DataType="System.Boolean"
            HeaderText="Owner" SortExpression="Owner" UniqueName="Owner">
        </telerik:GridCheckBoxColumn>
    </Columns>
</MasterTableView>
    </telerik:RadGrid>


DataSource:
    <asp:AccessDataSource ID="AccessDataSource2" runat="server"
        DataFile="~/App_Data/HomeOwners.mdb"
        SelectCommand="SELECT * FROM [tblResidents] WHERE ([Address] = ?) ORDER BY [FirstName]"
        ConflictDetection="CompareAllValues"
        DeleteCommand="DELETE FROM [tblResidents] WHERE [ID] = ? AND (([Address] = ?) OR ([Address] IS NULL AND ? IS NULL)) AND (([FirstName] = ?) OR ([FirstName] IS NULL AND ? IS NULL)) AND (([LastName] = ?) OR ([LastName] IS NULL AND ? IS NULL)) AND (([Email] = ?) OR ([Email] IS NULL AND ? IS NULL)) AND (([Company] = ?) OR ([Company] IS NULL AND ? IS NULL)) AND (([JobFunction] = ?) OR ([JobFunction] IS NULL AND ? IS NULL)) AND [Resident] = ? AND [Owner] = ?"
        InsertCommand="INSERT INTO [tblResidents] ([ID], [Address], [FirstName], [LastName], [Email], [Company], [JobFunction], [Resident], [Owner]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"
        UpdateCommand="UPDATE [tblResidents] SET [FirstName] = ?, [LastName] = ?, [Email] = ?, [Company] = ?, [JobFunction] = ?, [Resident] = ?, [Owner] = ? WHERE [ID] = ?">
        <DeleteParameters>
            <asp:Parameter Name="original_ID" Type="Int32" />
            <asp:Parameter Name="original_Address" Type="String" />
            <asp:Parameter Name="original_Address" Type="String" />
            <asp:Parameter Name="original_FirstName" Type="String" />
            <asp:Parameter Name="original_FirstName" Type="String" />
            <asp:Parameter Name="original_LastName" Type="String" />
            <asp:Parameter Name="original_LastName" Type="String" />
            <asp:Parameter Name="original_Email" Type="String" />
            <asp:Parameter Name="original_Email" Type="String" />
            <asp:Parameter Name="original_Company" Type="String" />
            <asp:Parameter Name="original_Company" Type="String" />
            <asp:Parameter Name="original_JobFunction" Type="String" />
            <asp:Parameter Name="original_JobFunction" Type="String" />
            <asp:Parameter Name="original_Resident" Type="Boolean" />
            <asp:Parameter Name="original_Owner" Type="Boolean" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="ID" Type="Int32" />
            <asp:Parameter Name="Address" Type="String" />
            <asp:Parameter Name="FirstName" Type="String" />
            <asp:Parameter Name="LastName" Type="String" />
            <asp:Parameter Name="Email" Type="String" />
            <asp:Parameter Name="Company" Type="String" />
            <asp:Parameter Name="JobFunction" Type="String" />
            <asp:Parameter Name="Resident" Type="Boolean" />
            <asp:Parameter Name="Owner" Type="Boolean" />
        </InsertParameters>
        <SelectParameters>
            <asp:SessionParameter Name="Address" SessionField="Address" Type="String" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="FirstName" Type="String" />
            <asp:Parameter Name="LastName" Type="String" />
            <asp:Parameter Name="Email" Type="String" />
            <asp:Parameter Name="Company" Type="String" />
            <asp:Parameter Name="JobFunction" Type="String" />
            <asp:Parameter Name="Resident" Type="Boolean" />
            <asp:Parameter Name="Owner" Type="Boolean" />
            <asp:Parameter Name="ID" Type="Int32" />
        </UpdateParameters>
    </asp:AccessDataSource>

1 Answer, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 21 Jul 2010, 03:10 PM
Hello Kyle,

You can examine the help article below, which elaborates on this subject and see if it helps:
http://www.telerik.com/help/aspnet-ajax/grdinsertupdatedeleteatdatabaselevel.html

All the best,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
kyle goodfriend
Top achievements
Rank 2
Answers by
Pavlina
Telerik team
Share this question
or