2011-09-20 65 views
1

我有一個帶有簡單表單視圖和對象數據源的.Net 3.5應用程序。ObjectDataSource中沒有Id更新方法Parrameter

<asp:ObjectDataSource ID="odsDevice" runat="server" SelectMethod="GetDeviceByDeviceNumber" EnableViewState="True" 
    UpdateMethod="updateDevice" DataObjectTypeName="GPSO.Repository.Device" TypeName="GPSOnline.ATOMWebService"> 
<SelectParameters> 
    <asp:SessionParameter DbType="Guid" Name="deviceid" SessionField="deviceid" /> 
</SelectParameters> 

和這裏的形式爲圖

<asp:FormView ID="fvDevices" runat="server" DataSourceID="odsDevice"> 
<EditItemTemplate> 
    <table cellpadding="0" cellspacing="0" class="AdminContent"> 
     <tr> 
      <td class="Content"> 
       <h1> 
        Device Details</h1> 
       <hr /> 
       <table class="AdminDetails" cellpadding="0" cellspacing="0"> 
        <tr> 
         <th> 
          Atom Serial # 
         </th> 
         <td class="control"> 
          <asp:TextBox ID="txtDeviceNumber" runat="server" Text='<%#Bind("DeviceNumber")%>' /> 
         </td> 
        </tr> 
        <tr> 
         <th> 
          &nbsp; 
         </th> 
         <td class="control"> 
          <asp:RequiredFieldValidator ID="rfvDeviceNumber" runat="server" ToolTip="Must specify Device Number" 
           Display="Dynamic" ErrorMessage="Device Number is Required" EnableClientScript="false" 
           ControlToValidate="txtDeviceNumber"></asp:RequiredFieldValidator> 
          <asp:RegularExpressionValidator ID="revDeviceAddId" runat="server" ToolTip="Device ID must be an Integer." 
           ValidationExpression="[0-9]{1,6}" Display="Dynamic" ErrorMessage="Device ID must be an Number, less then 1000000." 
           EnableClientScript="false" ControlToValidate="txtDeviceNumber"></asp:RegularExpressionValidator> 
          <asp:CustomValidator ID="cvDeviceAddId" runat="server" ErrorMessage="Device ID already Exists." 
           Display="Dynamic" ToolTip="Device ID already Exists." ControlToValidate="txtDeviceNumber" 
           OnServerValidate="CheckDeviceDoesNotExist"></asp:CustomValidator> 
         </td> 
        </tr> 
        <tr> 
         <th> 
          &nbsp; 
         </th> 
         <td class="control"> 
          <asp:Label runat="server" ForeColor="Red" ID="lblFeedback" Text="" /> 
         </td> 
        </tr> 
        <tr> 
         <th> 
          &nbsp; 
         </th> 
         <td class="control"> 
          &nbsp; 
         </td> 
        </tr> 
        <tr> 
         <th> 
          &nbsp; 
         </th> 
         <td class="control"> 
          <asp:Button runat="server" ID="btnUpdate" Text="Update" CausesValidation="true" CommandName="Update" 
           Width="160px" /> 
         </td> 
        </tr> 
       </table> 
      </td> 
     </tr> 
    </table> 
</EditItemTemplate> 

,這裏是用於對象數據源的方法的代碼。

[OperationContract] 
    [WebGet] 
    public void updateDevice(Device device) 
    { 
     DeviceRep.updateDevice(device); 

    } 

    [OperationContract] 
    [WebGet] 
    public Device GetDeviceByDeviceNumber(Guid deviceid) 
    { 
     return DeviceRep.GetDeviceByDeviceNumber(deviceid);} 

現在的業務對象包含了我不感興趣的更新遠幾場,我才真正要更新設備號。

但是,我的問題是,我作爲參數進入「公共無效updateDevice(設備設備)」方法的設備對象沒有正在更新的對象的ID。這使得無法知道存儲庫中的哪個記錄要更新。

是否有一種方法來保持設備的ID,以便在更新時更新其對象的部分?

回答

2

不知道,但你必須設置的FormViewDataKeyNames財產,

<asp:FormView ID="fvDevices" runat="server" 
    DataSourceID="odsDevice" DataKeyNames="deviceid" .. 
相關問題