views:

670

answers:

2

I am tried to create a data list display all cuisine in alphabetical order in column however i couldn't find the way to do it, can any one help.

using data list or repeater in asp.net only allow you to display in horizontal or vertical alphabetical order for example

Afghan       Asian    Burmese    Cambodian
Chinese     Croatian  European  French
Greek            Indian  International  Italian

What I want to have is

Afghan      Chinese      Greek
Asian       Croatian     Indian 
Burmese     European     International 
Cambodian   French       Italian

Thank you

A: 

What I'd do is get your list in alphabetical order, and then rearrange such that when you use the datalist/repeater default ordering, it's in your desired format.

In bizarre pseudo-code.

/*
your input is A,B,C,D,E,F,G,H,I,J,K,L

given this order, it returns:

A, B, C
D, E, F
G, H, I
J, K, L

but you want

A, E, I
B, F, J
C, G, K
D, H, L

So you need to change your input to this:

A,E,I,B,F,J,C,G,K,D,H,L

*/

let numColumns = 3;
let numItems = 12;
let itemsPerColumn = numItems / numColumns;

loop i from 0 to itemsPerColumn - 1
    loop j from 0 to numColumns - 1
        newOrdering.push(oldOrdering[i * numColumns + j])

There might be some nifty .NET feature to change the ordering style, but this is just one old-school method.

PS: This is working on the best case scenario, which is that the number of items is evenly divisible by the number of columns. You'll have to adjust somewhat for different values.

nickf
A: