質問

私はPKを保存する隠し、読み取り専用列が含まれ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'、供給されなかったと予想している。

私はそれが正常に動作しますが、その後、ユーザが希望されていない主キーの値を編集することができますに読み取り専用=「false」に設定した場合。私は背後にあるコードでの回避策を知っているが、まっすぐなマークアップでそれを行うにはどのような方法はありますか?おかげます。

役に立ちましたか?

解決

あなたが試すことができます。

他の事は、グリッドのDataKeyNamesコレクションにpkWorkerIDフィールドを追加しています。それは編集上のストアドプロシージャにビューステートに保存され、自動的に渡す必要があります。

ディック

他のヒント

答えはpkWorkerID列のInEditModeにForceExtractValueを設定することです。

<telerik:GridBoundColumn DataField="pkWorkerID" HeaderText="pkWorkerID" UniqueName="pkWorkerID" SortExpression="pkWorkerID" Visible="false" ReadOnly="true" ForceExtractValue="InEditMode"></telerik:GridBoundColumn>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top