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

Radgrid update command not firing

1 Answer 456 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Calin
Top achievements
Rank 1
Calin asked on 28 Aug 2019, 03:04 PM

I have a radgrid storing key data from a SQL stored procedure. My grid is as follows:

      <telerik:RadGrid ID="keyGrid" runat="server" DataSourceID="Keys" AutoGenerateEditColumn="True">
            <GroupingSettings CollapseAllTooltip="Collapse all groups"></GroupingSettings>
                <MasterTableView AutoGenerateColumns="False" DataSourceID="Keys">
                    <Columns>
                        <telerik:GridBoundColumn DataField="SerialNumber" DataType="System.Int32" FilterControlAltText="Filter SerialNumber column" HeaderText="SerialNumber" SortExpression="SerialNumber" UniqueName="SerialNumber" ReadOnly="True"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Type" FilterControlAltText="Filter Type column" HeaderText="Type" SortExpression="Type" UniqueName="Type" ReadOnly="True"></telerik:GridBoundColumn>
                        <telerik:GridTemplateColumn DataField="Status" FilterControlAltText="Filter Status column" HeaderText="Status" SortExpression="Status" UniqueName="Status">
                            <EditItemTemplate>
                                <asp:DropDownList ID="DropDownList1" runat="server">
                                    <asp:ListItem>Assigned</asp:ListItem>
                                    <asp:ListItem>Lost</asp:ListItem>
                                    <asp:ListItem>Lost and Reassigned</asp:ListItem>
                                    <asp:ListItem>Returned</asp:ListItem>
                                </asp:DropDownList>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="StatusLabel" runat="server" Text='<%# Eval("Status") %>'></asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridBoundColumn DataField="ApprovedBy" FilterControlAltText="Filter ApprovedBy column" HeaderText="ApprovedBy" SortExpression="ApprovedBy" UniqueName="ApprovedBy" ReadOnly="True"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="DateTime" FilterControlAltText="Filter DateTime column" HeaderText="DateTime" SortExpression="DateTime" UniqueName="DateTime" DataType="System.DateTime" ReadOnly="True"></telerik:GridBoundColumn>
                          </Columns>
        </MasterTableView>
           </telerik:RadGrid>

 

I have set up the update command through the data source configuration wizard, same as how I set up my data source for the grid itself. Code follows:

            <asp:SqlDataSource ID="Keys" runat="server" ConnectionString="<%$ ConnectionStrings:KeyTracking.My.MySettings.dbKeyTracking %>" SelectCommand="sp_Show_keys" SelectCommandType="StoredProcedure" UpdateCommand="sp_Update_key" UpdateCommandType="StoredProcedure">
             
                
                <SelectParameters>
                    <asp:ControlParameter ControlID="employeeCB" Name="empID" PropertyName="SelectedValue" Type="Int32" />
                </SelectParameters>
                <UpdateParameters>
                    <asp:Parameter Name="empNo" Type="Int32" />
                    <asp:Parameter Name="status" Type="String" />
                </UpdateParameters>
            </asp:SqlDataSource>

 

When I hit edit in my grid column, it pops up as it should, only editing Key Status. That is the only thing that will need updating. I can select a new value in the drop box that populates, hit save, and it close. The problem is, it does not refresh my radgrid to show the update. I am using an update procedure to perfom the update to the database, as follows:

CREATE proc [dbo].[sp_Update_key]
(@empNo as Int,
@status as varchar (50),
@SN as Int,
@type as varchar (50),
@approved as varchar (50),
@datetime as datetime
)

as

begin

update dbo.Keys
set Status=@status

where EmpID=@empNo
end 
GO

 

Where am I going wrong here?

I am still new and learning, so I can't quite figure out where things aren't firing correctly. 

 

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 02 Sep 2019, 10:53 AM
Hello Calin,

Generally, for the Updating process to work automatically, the AllowAutomaticUpdates property should be enabled:
https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/data-editing/automatic-datasource-operations

However, in this case you are using Stored Procedures. I am afraid Stored Procedures are not supported with automatic CRUD operations. Therefore, you can keep the AllowAutomaticUpdates to be false and use the UpdateCommand, InsertCommand or ItemCommand event handlers to get the required values and initiate the update manually in the stored procedure query method call.

You can make avail of the ExtractValues method:
https://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/manual-crud-operations/defaultcs.aspx

Or extract the values from the individual controls similar to this sample:
https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/data-editing/database-level-editing

You can also check:
https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-controls-in-editinsert-mode


I hope this information will be helpful. Let me know if I can help with anything else.

Regards,
Eyup
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
General Discussions
Asked by
Calin
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or