سؤال

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. هنا مقتطف من علامات 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 '، والتي لم يتم توفيرها.

إذا قمت بضبط Readonly = "False" على أنه يعمل بشكل جيد ولكن المستخدم يمكن للمستخدم تحرير قيمة المفتاح الأساسية غير المرغوب فيها. أعرف أن العمل حولها في الرمز وراء ولكن هل هناك أي طريقة للقيام بذلك مباشرة في العلامات؟ شكرًا.

هل كانت مفيدة؟

المحلول

شيء آخر يمكنك محاولةه هو إضافة حقل PKWorkerID إلى مجموعة Datakeynames من الشبكة. يجب تخزينها في ViewState وتم تمريرها تلقائيا إلى الإجراء المخزن عند التحرير.

ديك.

نصائح أخرى

الجواب هو تعيين 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