I am curious as to how one might keep a row hidden from the end user but still have it included in the update process of a detailsview control in asp.net. I have the following fields in the DetailsView control.

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

When SupplierID's Visibility is set to false then the row no longer updates. Setting it to true allows the application to update as normal. I would've even thought that given the below configuration that both PropertyID and SupplierID could be exempt from the details view, but removing the fields outright stops it from updating as well.

I have the following update parameters in place.

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

And my update command is as follows:

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

Yet despite the fact that the query is set up to use the ID obtained from a query string parameter, the record fails to update if a SupplierID field is missing from the details view or invisible to the user.

Can someone please provide some insight as how I should fix this?

有帮助吗?

解决方案

Ah, it would appear that I should've changed the WHERE clause in the UpdateCommand to check supplierID against the querystringparameter, not the original_propertyID parameter.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top