Tuesday, July 31, 2007

Sorting By "Random"

I had been trying to figure out a way to sort the pictures that I have in a database randomly. I knew that you could choose to order them according to a specific id in ascending or descending order. But, I did not know that you could simply use the code "Order By NEWID()" in the select statement to accomplish this. As a result, I ended up with the following:

itemtemplate
asp:label runat="server" id="lblPics" text='<%# Eval("Pictures") %>'>
asp:label
itemtemplate

...and then use the sql select command,

SELECT [Pictures] FROM [My_Photos] Order By NEWID()


...pretty cool.

3 comments:

Anonymous said...

hey good tip. I always used a temporary table for this....kel

Jeffrey J Way said...

Yeah...I thought it would be much more difficult to implement this...but it was pretty simple.

Jeffrey J Way said...

How's Sean doing?