locked
ListView Template Parameters Different RRS feed

  • Question

  • User-1193791088 posted
    <asp:SqlDataSource ID="SqlData_CoItemPrice" runat="server" ConnectionString='<%$ ConnectionStrings:MySolutionsCnSt %>' SelectCommand="SELECT * FROM [CoItemPrice] WHERE ([ItemId] = @ItemId)" UpdateCommand="CoItemsPrice_Upd" UpdateCommandType="StoredProcedure">
    					<SelectParameters>
    						<asp:QueryStringParameter QueryStringField="ItemId" Name="ItemId" Type="String"></asp:QueryStringParameter>
    					</SelectParameters>
    					<UpdateParameters>
    						<asp:Parameter Name="ItemId" Type="String"></asp:Parameter>
    						<asp:Parameter Name="PurchasePrice" Type="Decimal"></asp:Parameter>
    						<asp:Parameter Name="ShippingPaid" Type="Decimal"></asp:Parameter>
    						<asp:Parameter Name="CountyId" Type="Int32"></asp:Parameter>
    						<asp:Parameter Name="TaxTypeId" Type="Int32"></asp:Parameter>
    					</UpdateParameters>
    				</asp:SqlDataSource>

    The two parameters CountyId and TaxTypeId are not stored in a table but used in a stored procedure to figure out computed columns.

    					<EditItemTemplate>
    						<div class="col-sm-12 col-xxl-6 form-group">
    							<div class="col-sm-12 col-md-3">
    								<label class="col-form-label w-100 text-primary" for="uiPurchasePrice">Purchase Price:</label>
    							</div>
    							<div class="col-sm-12 col-md-8">
    								<asp:TextBox Text='<%# Bind("PurchasePrice") %>' runat="server" ID="uiPurchasePrice" />
    							</div>
    							<div class="col-sm-12 col-md-1">
    								<asp:RequiredFieldValidator ID="rfPurchasePrice" runat="server" ControlToValidate="uiPurchasePrice" ValidationGroup="EditCoItemsPrice" SkinID="Icon" />
    							</div>
    						</div>
    						<div class="col-sm-12 col-xxl-6 form-group">
    							<div class="col-sm-12 col-md-3">
    								<label class="col-form-label w-100 text-primary" for="uiCountyId">County Purchased:</label>
    							</div>
    							<div class="col-sm-12 col-md-8">
    								<asp:DropDownList SelectedValue='<%# Bind("CountyId") %>' runat="server" ID="uiCountyId" DataSourceID="SqlData_CountyId" DataTextField="CountyName" DataValueField="CountyId" AppendDataBoundItems="true" >
    									<asp:ListItem Text="SELECT" Value="" />
    								</asp:DropDownList>
    							</div>
    							<div class="col-sm-12 col-md-1">
    								<asp:RequiredFieldValidator ID="rfCountyId" runat="server" ControlToValidate="uiCountyId" ValidationGroup="EditCoItemsPrice" SkinID="Icon" InitialValue="-1" />
    							</div>
    						</div>
    						<div class="col-sm-12 col-xxl-6 form-group">
    							<div class="col-sm-12 col-md-3">
    								<label class="col-form-label w-100 text-primary" for="uiShippingPaid">Shipping Paid:</label>
    							</div>
    							<div class="col-sm-12 col-md-8">
    								<asp:TextBox Text='<%# Bind("ShippingPaid") %>' runat="server" ID="uiShippingPaid" />
    							</div>
    							<div class="col-sm-12 col-md-1">
    								<asp:RequiredFieldValidator ID="rfShippingPaid" runat="server" ControlToValidate="uiShippingPaid" ValidationGroup="EditCoItemsPrice" SkinID="Icon" />
    							</div>
    						</div>
    						<div class="col-sm-12 col-xxl-6 form-group">
    							<div class="col-sm-12 col-md-3">
    								<label class="col-form-label w-100 text-primary" for="uiCountyId">Tax Type:</label>
    							</div>
    							<div class="col-sm-12 col-md-8">
    								<asp:DropDownList SelectedValue='<%# Bind("TaxTypeId") %>' runat="server" ID="uiTaxTypeId" DataSourceID="SqlData_ItemTaxTypeId" DataTextField="TaxType" DataValueField="TaxTypeId" AppendDataBoundItems="true">
    									<asp:ListItem Text="SELECT" Value="" />
    								</asp:DropDownList>
    							</div>
    							<div class="col-sm-12 col-md-1">
    								<asp:RequiredFieldValidator ID="rfTaxTypeId" runat="server" ControlToValidate="uiTaxTypeId" ValidationGroup="EditCoItemsPrice" SkinID="Icon" InitialValue="-1" />
    							</div>
    						</div>
    						<div class="col-sm-12 clearfix">
    							<asp:Button runat="server" CommandName="Update" ID="UpdateButton" SkinID="FormSave" CausesValidation="true" ValidationGroup="EditCoItemsPrice" />
    							<asp:Button runat="server" CommandName="Cancel" ID="CancelButton" SkinID="FormCancel" CausesValidation="false" />
    						</div>
    					</EditItemTemplate>

    Even though the values are supplied using DropDownLists It wont Bind because System.DataRow does not contain property CountyId - I thought the only value that had to be the same was the primary key value.

    I even tried

    <SelectParameters>
    						<asp:QueryStringParameter QueryStringField="ItemId" Name="ItemId" Type="String"></asp:QueryStringParameter>
    						<asp:Parameter Name="CountyId" Type="Int32" DefaultValue="0" />
    						<asp:Parameter Name="TaxTypeId" Type="Int32" DefaultValue="0" />
    					</SelectParameters>

    But that doesnt work.

    CREATE TABLE [dbo].[CoItemPrice] (
        [ItemId]        NVARCHAR (128) NOT NULL,
        [PurchasePrice] MONEY          DEFAULT ((0.0000)) NOT NULL,
        [SalesTaxPaid]  MONEY          DEFAULT ((0.0000)) NOT NULL,
        [ShippingPaid]  MONEY          DEFAULT ((0.0000)) NOT NULL,
        [HandlingFee]   MONEY          DEFAULT ((0.0000)) NOT NULL,
        [SalesPrice]    AS             ((([PurchasePrice]+[SalesTaxPaid])+[ShippingPaid])+[HandlingFee]) PERSISTED NOT NULL,
        PRIMARY KEY CLUSTERED ([ItemId] ASC),
        CONSTRAINT [FK_CoItemPrice_CoItems_ItemId] FOREIGN KEY ([ItemId]) REFERENCES [dbo].[CoItems] ([ItemId]) ON UPDATE CASCADE
    );
    CREATE PROCEDURE [dbo].[CoItemsPrice_Upd] (
    @ItemId			NVARCHAR(128),
    @PurchasePrice	MONEY,
    @ShippingPaid   MONEY,
    @CountyId		INT,
    @TaxTypeId		INT
    ) AS
    BEGIN
    DECLARE @StatusCode INT;
    BEGIN TRY
    BEGIN TRANSACTION
    -- +-----------------------------------------------------------
    DECLARE @SalesPrice MONEY, @SalesTaxPaid MONEY, @HandlingFee MONEY, @SalesTaxRate DECIMAL(7,4)
    DECLARE @ItemGroupId INT = (SELECT ItemGroupId FROM CoItems WHERE ItemId = @ItemId)
    
    -- REMOVE AFTER INITIAL INSERT
    --DELETE FROM CoItemPrice WHERE ItemId = @ItemId
    
    SELECT @SalesTaxRate = SalesTax FROM DataLocCounty WHERE CountyId = @CountyId
    -- SELECT DEFAULT TAX RATE
    IF (@SalesTaxRate IS NULL)
    BEGIN
    SELECT @SalesTaxRate = 0.0800
    END
    
    IF (@TaxTypeId = 0)
    BEGIN
    SELECT @SalesTaxRate = 0.0000
    END
    SELECT @SalesTaxPaid = @PurchasePrice * @SalesTaxRate 
    -- +-----------------------------------------------------------
    IF( @PurchasePrice <= 5.0000)
    BEGIN
    SELECT @HandlingFee =  (@PurchasePrice * .10)
    END 
    IF (@PurchasePrice BETWEEN 5.0001 AND 10.0000)
    BEGIN
    SELECT @HandlingFee =  1.0000
    END 
    IF (@PurchasePrice > 10.0001)
    BEGIN
    SELECT @HandlingFee =  2.0000
    END
    IF (@ItemGroupId BETWEEN 164 AND 171) -- BLINDS
    BEGIN
    SELECT @HandlingFee =  5.0000
    END
    -- +-----------------------------------------------------------
    UPDATE CoItemPrice SET PurchasePrice = @PurchasePrice, SalesTaxPaid = @SalesTaxPaid, ShippingPaid = @ShippingPaid, HandlingFee = @HandlingFee WHERE ItemId = @ItemId
    -- +-----------------------------------------------------------
    COMMIT TRANSACTION;
    SELECT @StatusCode = 0
    END TRY
    -- +-----------------------------------------------------------
    BEGIN CATCH
        IF @@TRANCOUNT > 0
        ROLLBACK TRANSACTION;
        INSERT INTO [WebLogErrorsSql] (ErrorNumber,ErrorLine,ErrorMessage,ErrorSeverity,ErrorState,ProcedureName)
    	VALUES (ERROR_NUMBER(), ERROR_LINE(), ERROR_MESSAGE(), ERROR_SEVERITY(), ERROR_STATE(), OBJECT_NAME(@@PROCID)); 
    	SELECT @StatusCode = -1;
    END CATCH
    -- +-----------------------------------------------------------
    RETURN @StatusCode
    END

    I tried to use ControlParameter but it couldnt Find the Control

    Wednesday, February 8, 2017 3:53 AM

All replies

  • User1324658857 posted

    Hi,

    which error you meet now, please be brief!

    Thursday, February 9, 2017 8:01 AM