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