我有绑定到包括存储的pK a隐藏,只读列一个SqlDataSource一个radgrid控件。我想通过绑定到该列进行更新,存储过程,但默认行为的值时,该列是只读的,不是参数传递给SqlDataSource的。我的问题是,是否有通过该值,而不必进入后面的代码的方式。这是我的asp标记的片段。

<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>

在存储过程原型看起来像这样:

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

当我运行页面,并尝试编辑记录我收到以下错误:

过程或函数 'spFinancialSystemMapWorkerToCode' 预计参数 '@pkWorkerID',但未提供。

如果我设置只读=“假”在它工作正常,但然后用户可以编辑这是不期望的主键值。我知道在后面的代码工作变通,但有什么办法做到这一点直直的标记?感谢。

有帮助吗?

解决方案

您可以尝试其他的事情是pkWorkerID字段添加到网格的DataKeyNames集合。应当存储在视图状态和自动传递给上编辑该存储过程。

迪克

其他提示

答案是到ForceExtractValue设置为InEditMode为pkWorkerID柱

<telerik:GridBoundColumn DataField="pkWorkerID" HeaderText="pkWorkerID" UniqueName="pkWorkerID" SortExpression="pkWorkerID" Visible="false" ReadOnly="true" ForceExtractValue="InEditMode"></telerik:GridBoundColumn>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top