0

行をエンド ユーザーから非表示にしながら、asp.net の詳細ビュー コントロールの更新プロセスに行を含める方法に興味があります。DetailsView コントロールに次のフィールドがあります。

<Fields>
    <asp:BoundField DataField="PropertyID" HeaderText="Property ID" SortExpression="PropertyID" InsertVisible="False" ReadOnly="True" Visible="False" />
    <asp:BoundField DataField="SupplierID" HeaderText="Supplier ID" SortExpression="SupplierID" InsertVisible="False" ReadOnly="True" Visible="False" />
    <asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
    <asp:BoundField DataField="AddressUnit" HeaderText="Suite/Unit" SortExpression="AddressUnit" />
    <asp:BoundField DataField="AddressCity" HeaderText="City" SortExpression="AddressCity" />
    <asp:BoundField DataField="AddressProvince" HeaderText="Province" SortExpression="AddressProvince" />
    <asp:BoundField DataField="AddressPostalCode" HeaderText="Postal Code" SortExpression="AddressPostalCode" />
    <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
    <asp:BoundField DataField="Fax" HeaderText="Fax" SortExpression="Fax" />
    <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowInsertButton="True" />
</Fields>

SupplierID の Visibility が false に設定されている場合、行は更新されなくなります。true に設定すると、アプリケーションは通常どおり更新できます。以下の構成では、PropertyID と SupplierID の両方が詳細ビューから除外される可能性があると考えていましたが、フィールドを完全に削除すると更新も停止します。

次の更新パラメータが用意されています。

<UpdateParameters>
    <asp:QueryStringParameter Name="SupplierID" QueryStringField="ID" Type="Int32" />
    <asp:Parameter Name="Address" Type="String" />
    <asp:Parameter Name="AddressUnit" Type="String" />
    <asp:Parameter Name="AddressCity" Type="String" />
    <asp:Parameter Name="AddressProvince" Type="String" />
    <asp:Parameter Name="AddressPostalCode" Type="String" />
    <asp:Parameter Name="Phone" Type="String" />
    <asp:Parameter Name="Fax" Type="String" />
    <asp:Parameter Name="original_PropertyID" Type="Int32" />
    <asp:Parameter Name="original_SupplierID" Type="Int32" />
    <asp:Parameter Name="original_Address" Type="String" />
    <asp:Parameter Name="original_AddressUnit" Type="String" />
    <asp:Parameter Name="original_AddressCity" Type="String" />
    <asp:Parameter Name="original_AddressProvince" Type="String" />
    <asp:Parameter Name="original_AddressPostalCode" Type="String" />
    <asp:Parameter Name="original_Phone" Type="String" />
    <asp:Parameter Name="original_Fax" Type="String" />
</UpdateParameters>

そして、私の更新コマンドは次のとおりです。

UpdateCommand="UPDATE [SupplierProperty] SET [Address] = @Address, [AddressUnit] = @AddressUnit, [AddressCity] = @AddressCity, [AddressProvince] = @AddressProvince, [AddressPostalCode] = @AddressPostalCode, [Phone] = @Phone, [Fax] = @Fax WHERE [PropertyID] = @original_PropertyID AND [SupplierID] = @original_SupplierID AND [Address] = @original_Address AND (([AddressUnit] = @original_AddressUnit) OR ([AddressUnit] IS NULL AND @original_AddressUnit IS NULL)) AND [AddressCity] = @original_AddressCity AND [AddressProvince] = @original_AddressProvince AND [AddressPostalCode] = @original_AddressPostalCode AND [Phone] = @original_Phone AND (([Fax] = @original_Fax) OR ([Fax] IS NULL AND @original_Fax IS NULL))"

ただし、クエリ文字列パラメーターから取得した ID を使用するようにクエリが設定されているにもかかわらず、SupplierID フィールドが詳細ビューにないか、ユーザーに表示されない場合、レコードは更新されません。

これを修正する方法について、誰かが洞察を提供してもらえますか?

4

1 に答える 1

0

ああ、UpdateCommand の WHERE 句を変更して、original_propertyID パラメーターではなく、querystring パラメーターに対して SupplierID をチェックする必要があったようです。

于 2013-06-25T03:24:18.960 に答える