2009-11-04 71 views
1

我有一个绑定到SqlDataSource的radgrid,它包含一个存储pk的隐藏只读列。我想将绑定到该列的值传递给更新的存储过程,但列只读时的默认行为不是将参数传递给sqlDataSource。我的问题是,是否有一种方法可以在不需要进入代码的情况下传递该值。这里是我的asp标记的片段。将readonly radgrid列的值传递给存储过程

<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”它的工作正常,但然后用户可以编辑不需要的主键值。我知道在代码背后解决问题,但是有没有办法在标记中直接使用它?谢谢。

回答

1

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

迪克

+0

我最后不得不因为即使ForceExtractValue =“始终” pkWorkerID没有得到这样做传递给删除存储过程 – 2009-11-05 16:49:16

4

答案是设置ForceExtractValue到InEditMode为pkWorkerID列

<telerik:GridBoundColumn DataField="pkWorkerID" HeaderText="pkWorkerID" UniqueName="pkWorkerID" SortExpression="pkWorkerID" Visible="false" ReadOnly="true" ForceExtractValue="InEditMode"></telerik:GridBoundColumn> 
+0

我会接受这个答案,但不能2天所以有人忍者我的答案,让名气:d – 2009-11-04 17:51:43