Question

I have a radgrid bound to a SqlDataSource that includes a hidden, readonly column that stores a pk. I want to pass the value bound to that column to a stored procedure for Updates but the default behavior when the column is readonly is not to pass the parameter to the sqlDataSource. My question is whether there is a way to pass that value without having to go into the code behind. Here is a snippet of my asp markup.

<telerik:RadGrid ID="rgEmployees" runat="server" AutoGenerateColumns="False" 
        DataSourceID="sdsEmployees" GridLines="None" AllowAutomaticUpdates="true" AllowAutomaticDeletes="true">
        <MasterTableView DataSourceID="sdsEmployees" EditMode="EditForms">
            <Columns>
                <telerik:GridEditCommandColumn ButtonType="ImageButton" HeaderStyle-Width="20px"
                    UniqueName="Edit" HeaderText="Edit">
                    <HeaderStyle Width="10px"></HeaderStyle>
                    <ItemStyle HorizontalAlign="Center" Width="10px" />                        
                </telerik:GridEditCommandColumn>
                <telerik:GridBoundColumn DataField="pkWorkerID" HeaderText="pkWorkerID" UniqueName="pkWorkerID" SortExpression="pkWorkerID" Visible="false" ReadOnly="true"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="ContractManagerName" HeaderText="ContractManager Name" UniqueName="ContractManagerName" SortExpression="ContractManagerName" Visible="true" ReadOnly="true"></telerik:GridBoundColumn>
                <telerik:GridDropDownColumn 
                    DataField="CODE" 
                    HeaderText="Financial Software Name" 
                    DataSourceID="sdsFinancialSystemGetUnassignedWorkers" 
                    ListTextField="NAME" 
                    ListValueField="CODE" 
                    EnableEmptyListItem="true"
                    DropDownControlType="RadComboBox">                                            
                 </telerik:GridDropDownColumn>                     
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>
<asp:SqlDataSource ID="sdsEmployees" runat="server"
            ConnectionString="" ProviderName="System.Data.SqlClient" 
            SelectCommand="spFinancialSystemGetWorkerMappingDataSource" SelectCommandType="StoredProcedure" 
            UpdateCommand="spFinancialSystemMapWorkerToCode" UpdateCommandType="StoredProcedure" 
            DeleteCommand="spFinancialSystemRemoveWorkerMapping" DeleteCommandType="StoredProcedure">
            <SelectParameters>
                <asp:ControlParameter ControlID="hfpkSystemSupportedFinancialSoftware" Name="pkSystemSupportedFinancialSystems"
                    Type="Int32" />
            </SelectParameters>
            <UpdateParameters>
                <asp:ControlParameter ControlID="hfpkSystemSupportedFinancialSoftware" Name="pkSystemSupportedFinancialSystems"
                    Type="Int32" PropertyName="Value" />
                <asp:Parameter Name="pkWorkerID" Type="Int32" />
                <asp:Parameter Name="CODE" Type="String" />    
            </UpdateParameters>
            <DeleteParameters>
                <asp:ControlParameter ControlID="hfpkSystemSupportedFinancialSoftware" Name="pkSystemSupportedFinancialSystems"
                    Type="Int32" PropertyName="Value" />
                <asp:Parameter Name="pkWorkerID" Type="Int32" />                    
            </DeleteParameters>
        </asp:SqlDataSource>

The stored procedure prototype looks like this:

CREATE PROCEDURE [dbo].[spFinancialSystemMapWorkerToCode] 
@pkWorkerID int,
@pkSystemSupportedFinancialSystems int,
@CODE nvarchar(200)

When I run the page and try to edit a record I get the following error:

Procedure or function 'spFinancialSystemMapWorkerToCode' expects parameter '@pkWorkerID', which was not supplied.

If I set readonly="false" on the It works fine but then the user can edit the primary key value which is not desired. I know work arounds in code behind but is there any way to do it straight in the markup? Thanks.

Was it helpful?

Solution

Other thing you can try is add the pkWorkerID field to the DataKeyNames collection of the grid. It should be stored in the viewstate and passed automatically to the stored procedure on edit.

Dick

OTHER TIPS

The answer is to set the ForceExtractValue to InEditMode for the pkWorkerID column

<telerik:GridBoundColumn DataField="pkWorkerID" HeaderText="pkWorkerID" UniqueName="pkWorkerID" SortExpression="pkWorkerID" Visible="false" ReadOnly="true" ForceExtractValue="InEditMode"></telerik:GridBoundColumn>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top