Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all,
Vanilla are planning an update to the site on April 24th (next Wednesday). It is a major PHP8 update which is expected to boost performance across the site. The site will be down from 7pm and it is expected to take about an hour to complete. We appreciate your patience during the update.
Thanks all.

C# shopping basket, trying to remove an item...

Options
1234579

Comments

  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    I copied over the DropDownDemo.aspx and cs files just in case I changed something there by mistake and its still missing the last dropdown data so it isn't the code. It's probably something stupid I've done with the database table or SP's...


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Its an ID-Ten-T error on my part


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    I can't believe it wasn't something I did! ;-)


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Its a bit of column A and a bit of Column B

    ID != Id

    So in the select SubCat stored proc change the ID to Id to make it work...


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Ginger wrote: »
    Its a bit of column A and a bit of Column B

    ID != Id

    So in the select SubCat stored proc change the ID to Id to make it work...

    That sorted it out fair play to ya!


  • Advertisement
  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Now for the hard part! Is getting a selection from the DD list to appear in the shopping cart just a matter of adding a button to the DropDownDemo.aspx page and binding the DD List to the Cart on the Button_Click event?


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    You see the way that I bring back the info for all items. Create something similar to just bring back the items you want..

    So i created a link table

    Id, SpecId, ProductId
    int, int, int

    What this is you can have say 1 product that falls into many specs and this allows you to set that up.

    So when you have your Id of your spec you get the products that are associated with that, similar to get all products execpt you get only the ones that are belonging to that spec.

    Bind that list of products to a repeater similar to how i have done it in Catalog.aspx and then you are laughing because everything else works the same once you have the basic list.

    Originally I was going to put that in the same page but I wanted to show how its done first so people can see it working in its own way.

    You will need to set the Primary Key on Products to the ID field before running this script
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[SpecProduct](
    	[ID] [int] IDENTITY(1,1) NOT NULL,
    	[SpecID] [int] NOT NULL,
    	[ProductID] [int] NOT NULL
    ) ON [PRIMARY]
    GO
    /****** Object:  StoredProcedure [dbo].[usp_select_specProduct]    Script Date: 05/08/2009 12:38:59 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE PROCEDURE [dbo].[usp_select_specProduct]
    (
    @SpecID INT
    )
    AS
    SELECT Product.Id, Product.Name, Product.Description, Product.Cost
    FROM Product INNER JOIN SpecProduct ON Product.Id = SpecProduct.ProductID
    WHERE SpecProduct.SpecID = @SpecID
    GO
    /****** Object:  ForeignKey [FK_SpecProduct_Product]    Script Date: 05/08/2009 12:39:00 ******/
    ALTER TABLE [dbo].[SpecProduct]  WITH CHECK ADD  CONSTRAINT [FK_SpecProduct_Product] FOREIGN KEY([ProductID])
    REFERENCES [dbo].[Product] ([Id])
    GO
    ALTER TABLE [dbo].[SpecProduct] CHECK CONSTRAINT [FK_SpecProduct_Product]
    GO
    /****** Object:  ForeignKey [FK_SpecProduct_Spec]    Script Date: 05/08/2009 12:39:00 ******/
    ALTER TABLE [dbo].[SpecProduct]  WITH CHECK ADD  CONSTRAINT [FK_SpecProduct_Spec] FOREIGN KEY([SpecID])
    REFERENCES [dbo].[Spec] ([ID])
    GO
    ALTER TABLE [dbo].[SpecProduct] CHECK CONSTRAINT [FK_SpecProduct_Spec]
    GO
    

    You will then need to make sure that all your products have a spec (and its just numbers)

    Next thing is you will need to create a method in the data access layer that accepts an int and returns a list of products

    Same in the business layer

    Once you have that, you can copy the repeater and its code to get yourself up and running


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    I've a table I created yesterday called ProductSpec (ID, ProductID, SpecID, int, int,int), should I just drop this table and run the new SQL script above?


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Same same, just remember to add the keys and also change the stored proc...


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    But they are different names, the table I made yesterday is ProductSpec and in your script the table is called SpecProduct. I'd just want to make sure any other references to the table are valid. I'm going to drop the table and use your script as I don't trust myself with the keys...


  • Advertisement
  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Right, that's done, so I've a table called SpecProduct and I've a SP created to Select from that table...


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    The only thing I'm not sure about is that in my head I see this as being an "Event" based thing. Like you click a button and something happens on that event, am I right in looking at it like that?


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    make sure you look at how tho join is done as i did it in previous script. I thought i included a stored proc as well. The event idea is simply that. You tell the said that you are doing something ie an event. Most things are events such as the index changing or a button press or a post back for example. I will be offline tho for the next few days but i will probably have all this written for another blog post by monday


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Ginger wrote: »
    make sure you look at how tho join is done as i did it in previous script. I thought i included a stored proc as well. The event idea is simply that. You tell the said that you are doing something ie an event. Most things are events such as the index changing or a button press or a post back for example. I will be offline tho for the next few days but i will probably have all this written for another blog post by monday

    I'll see if I can get it up and running over the weekend. I've added a button to he DropDownDemo.aspx page, so just wondering do I put the databind code into the codebehind function for the button_click event handler?


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    see thats the thing you dont need a button you just need to bind the data to a repeater just like how catalog does it. In fact just copy out the repeater and related events to the dropdown file and databind it in the selectedindex changed event of the spec dropdown using the selected value in spec to get the correct products. Because the repeater is set up to add to the shopping cart and its in session it will carry across pages easily as long as you add cart items to it. Make sense


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    I'm almost there with it now...


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Ehhh sounds like you copied in namespaces and everything

    Copy in the repeater first from the source of Catalog.aspx

    then copy in the in the bits such as RepeaterEvent

    then add the Event handler in the init part...


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Ginger wrote: »
    Ehhh sounds like you copied in namespaces and everything

    Copy in the repeater first from the source of Catalog.aspx

    then copy in the in the bits such as RepeaterEvent

    then add the Event handler in the init part...

    Yeah I got that sorted out, I'm just trying to hook everything up now. It's all on the same page now which is progress!


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Ok

    I just finished adding the Dropdowns and all that to the Catalog page and showing how to bind the information correctly etc.

    I will be putting that up later today if I get a chance along with a post explaining how it all works


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Oki doki the updated solution file and explanation of how it hangs together is online here


  • Advertisement
  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    I think I've a small problem with one stored proc... I had one in your previous solution called usp_select_ProductSpec and I renamed that to usp_select_AllProductsBySpec...

    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[usp_select_AllProductsBySpec]
    (
    @SpecID INT
    )
    AS
    SELECT Product.Id, Product.Name, Product.Description, Product.Cost
    FROM Product INNER JOIN SpecProduct ON Product.Id = SpecProduct.ProductID
    WHERE SpecProduct.SpecID = @SpecID


    Does this look good? After I changed the SP name to usp_select_AllProductsBySpec, the solution would compile but when I use the Dropdown list, I don't get any items in the catalog, it could just be that I haven't populated the DB properly to work with the script but before I go looking at that, I just want to see if my stored proc is good...


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Looks fine..

    Just run the following query on the database

    SELECT Product.Id, Product.Name, Product.Description, Product.Cost
    FROM Product INNER JOIN SpecProduct ON Product.Id = SpecProduct.ProductID

    and see if it returns any rows.

    You will see then what products are matched to what specs and then that will allow you to select what dropdowns will show info

    If you look in the script you will see I prepopulated the table so you can see some info


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    i was going to try to populate the DB using the script you used but I don't have the AdventureWorks DB on my server so I couldn't copy the records over... I'm just installing it locally now...


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    I've noticed when I try to add more than one specialisation for a SubCat, by going into the spec table and changing the SubCatID value for two records to have the same SubCatID value, that when I compile, the value is there on the specialisation dropdown layer but if there are 2 options in the list and I try to select the second one, after I release the mouse, it just jumps back to the first option on the specialisation layer...

    1 Spec 1A1 1
    2 Spec 1A2 1
    3 Spec 1A3 2
    4 Spec 1B1 2
    5 Spec 4A1 3
    6 Spec 5A1 4
    7 Spec 5A2 5
    8 Spec 6A1 6

    Just wondering can I do this or have I made a mistake in what I'm doing? :confused::confused::confused:


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    In the one I have it works fine, I just changed it now so that the first 2 specs have a subcatid of 1 and they work fine.

    Did you use my particular code or your own?

    Also the data for all the products is in the script, so you dont required the adventureworks database


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Ginger wrote: »
    Looks fine..

    Just run the following query on the database

    SELECT Product.Id, Product.Name, Product.Description, Product.Cost
    FROM Product INNER JOIN SpecProduct ON Product.Id = SpecProduct.ProductID

    and see if it returns any rows.

    You will see then what products are matched to what specs and then that will allow you to select what dropdowns will show info

    If you look in the script you will see I prepopulated the table so you can see some info

    When I run that SQL script I get back 4 rows but they aren't showing up in my aspx page. Also when I try to allow two options for the bottom serialisation layer, I get two options in the list but like before when I take the cursor off the list, the bottom item selected jumps back to the first option on the bottom/3rd drop down list...


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    I found the problem or the have sort of found it...

    In one of my stored procs:

    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[usp_select_AllProductsBySpec]
    (
    @SpecID INT
    )
    AS
    SELECT Product.Id, Product.Name, Product.Description, Product.Cost
    FROM Product INNER JOIN SpecProduct ON Product.Id = SpecProduct.ProductID
    WHERE SpecProduct.SpecID = @SpecID

    The table is was called specProduct but the SP above referred to SpecProduct. This last line in the SP seems to be the problem...


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Here's where I've the problem...

    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[usp_select_AllProductsBySpec]
    (
    @SpecID INT
    )
    AS
    SELECT Product.Id, Product.Name, Product.Description, Product.Cost
    FROM Product INNER JOIN SpecProduct ON Product.Id = SpecProduct.ProductID
    WHERE SpecProduct.SpecID = @SpecID

    When I replace @SpecID above with a number, as in 1, 2 or 3 or whatever, I get the product with that ID. But when I just put in @SpecID, I don't get anything although I should get records back because my Spec table and my Product table have records with 1 as ID... :confused::confused::confused:

    I checked the ProductBl.cs file and the SpecID is referred to there with a small case specID, I was thinking that could be the problem but when I changed it, no difference...


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    When you run the page, view the source of it and see what values are being applied to the dropdown Specialisation. If all the value are 0, its a problem in the stored proc to get all the specialisations


  • Advertisement
  • Registered Users Posts: 2,931 ✭✭✭Ginger


    If your stored proc is the same as the one you previously posted ie

    ALTER PROCEDURE [dbo].[usp_select_spec]
    (
    @CatID INT
    )
    AS
    SELECT ID,[Name] FROM Spec WHERE SubCatID = @CatID


    Change ID to Id and it will work


Advertisement