2011-09-20 8 views
1

간단한 폼보기와 개체 데이터 원본을 가진 .Net 3.5 응용 프로그램이 있습니다. 여기 ObjectDataSource의 ID 없음 업데이트 매개 변수 매개 변수

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