Click here to Skip to main content
15,881,876 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hey guys, Im struggling with this problem and could do with some advice. Ive done some searching and havent found what im looking for so I figured this was the next stop.

After removing the unimportant parts my code looks something like this. the Ajax goes to my serverside GetProducts function which returns a serialized string of JSON. Which is a List of items which a Select statement filled from a SQL database.
JavaScript
$.ajax({
        type: 'POST',
        url: 'Answer.aspx/GetProducts',
        data: JSON.stringify({ id: ID }),
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        success: function (msg) {

        document.getElementById("hfProducts").value = msg.d;

        document.getElementById("ulList").innerHTML = "";
        var data = eval('(' + document.getElementById("hiddenfieldOfProducts").value + ')');

        $.each(data, function (i, item) {
        var message = "<li>" + 
                           "<div  style=" + " width:100%;" + ">" +
                           item.ProductName+"  £" + item.ProductPrice+
                            " </div> " + 
                      "</li>  ";

         document.getElementById("ulList").innerHTML += message;
         var newcontent = document.createElement('li');
          });
        }
 });


At some point in the process before I start displaying the List items in a long unorganised list.Now I want to split up the items and sort the data based off the Category of the product so It would output like this, with the bold text the category:

Food:
Chicken pie £4.00
Roast Dinner £7.00
Chilli and rice £5.00

Desert
Apple pie £2.00
Ice cream £3.00

KitchenWare
Wok £15.00
Pan £10.00

You get the idea, currently they come through in the order they were added to the database based off the unique ID, I want to split them up based off the item.Category and display them like above with the Category title above that section.

Can I get some advice on what im doing here? I've spent hours today trying to work on this problem without much success. Since C# doesn't allow you to return multiple lists at the same time in a return statement and I don't want to resort to a lot of repeating code I need advice from someone with more experience.#

Hopefully I was clear enough, Thanks in advance.
Posted
Updated 19-Feb-13 9:40am
v2

1 solution

What are the values in follwoing elements, because I'm confused
- hfProducts
- hiddenfieldOfProducts
 
Share this answer
 
Comments
Phoenix234 20-Feb-13 4:24am    
Oh I apologise, hfProducts was meant to be renamed to hiddenfieldOfProducts.

Its a hiddenfield where I store the data the JSON returns.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900