From: darylemacdonald on
Hi All

I am new to .Net and am battling with a very simple query. I am pulling an
image path from a SQL database using SqlDataSource. I use the control once at
the top of my page. I then repeat this query 3 times in my code using asp
repeater with the DataSourceID pointing to the same SqlDataSource. It all
works perfectly except for one thing.

I am trying to pull the image paths in random order so every time the page
reloads you see a different image that when you click on it enlarges. My code
displays perfectly but does not match the enlarged picture as every time I
use the repeater it reruns the query and pulls the random images in a
different order. How do I get the query to keep the same order until the page
reloads: Below please find my code

//----------------Query to the Database ---------------------------------//
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data
Source=Server;Initial Catalog=table;User ID=username;Password=sa"
SelectCommand="SELECT TOP 10 Image_big, Image_ID FROM Images WHERE Web =
'Game Lodge' ORDER BY NEWID() DESC">
</asp:SqlDataSource>
//----------------------------------------------------------------------------
-----//


//---------------------------------Preloading my images with Java ----//

var yourImages = [
<asp:Repeater runat="server" id="Repeater1" DataSourceID="SqlDataSource1">
<ItemTemplate>
["Images/Big/<%# DataBinder.Eval(Container.DataItem, "Image_big") %>"],
</ItemTemplate>
</asp:Repeater>
]// list images to preload

var preloadImages=[]
for(var i=0;i<yourImages.length;i++) {
preloadImages[i]=new Image()
preloadImages[i].src=yourImages[i]
}

//----------------------------------------------------------------------------
-----//


//-------------------------------Then I place the images that will be used to
enlarge the Images -------//

is1vArr=[
<asp:Repeater runat="server" id="Repeater2" DataSourceID="SqlDataSource1">
<ItemTemplate>
["Images/Big/<%# DataBinder.Eval(Container.DataItem, "Image_big") %>"],
</ItemTemplate>
</asp:Repeater>
]
//----------------------------------------------------------------------------
-----------------------------------------------------//

//------------Then I call the thumnail image with the click event into my
page -------------------------//
<div id="image_box" style="position:absolute;left:0px;top:0px;text-align:
center">
<asp:Repeater runat="server" id="Repeater3" DataSourceID="SqlDataSource1">
<ItemTemplate>
<img id="Pic<%# Container.ItemIndex%>" src="Images/<%# DataBinder.Eval
(Container.DataItem, "Image_big") %>" alt="" onclick="getBigPic(<%# Container.
ItemIndex%>)"/><br/>
</ItemTemplate>
</asp:Repeater>
</div>
//----------------------------------------------------------------------------
-----------------------------------------------------//

As I say I am very new to asp.net and would appreciate any help

From: Andy O'Neill on

"darylemacdonald" <u58906(a)uwe> wrote in message news:a564987d6f51c(a)uwe...
> Hi All
<<>>
> different order. How do I get the query to keep the same order until the
> page
> reloads: Below please find my code.

I reckon simplest:

Create a hidden field and bind it to your datasource.
Use that field to drive everything.
It'll always have the same value per page load.

From: darylemacdonald on
Thanks Andy I thought of this and will definitely give it a try, my only
problem is that I am calling 10 random records so I will have to figure out
how to do this for all 10 items without slowing the page down. I am trying to
look for setting a SelectParameter and calling that instead of the
SqlDataSource, does that make ant sense and can it be done?

Andy O'Neill wrote:
>> Hi All
><<>>
>> different order. How do I get the query to keep the same order until the
>> page
>> reloads: Below please find my code.
>
>I reckon simplest:
>
>Create a hidden field and bind it to your datasource.
>Use that field to drive everything.
>It'll always have the same value per page load.

From: Andy O'Neill on

"darylemacdonald" <u58906(a)uwe> wrote in message news:a56512db5a384(a)uwe...
> Thanks Andy I thought of this and will definitely give it a try, my only
> problem is that I am calling 10 random records so I will have to figure
> out
> how to do this for all 10 items without slowing the page down. I am trying
> to
> look for setting a SelectParameter and calling that instead of the
> SqlDataSource, does that make ant sense and can it be done?

No, I don't follow.