0

我很好奇如何对最终用户隐藏一行,但仍将其包含在 asp.net 中的 detailsview 控件的更新过程中。我在 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 子句以根据 querystring 参数检查供应商 ID,而不是 original_propertyID 参数。

于 2013-06-25T03:24:18.960 回答