Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
In my dataview i have 2 to 8 images.i am assigning these images to image control.
for eg:
imgFifth.ImageUrl = dv[r.Next(0, dv.Count - 1)][2].ToString();
ie randomly displaying images in the dataview.
but sometimes same images is appearing twice or thrice.
iwant to avoid it.
ie if 1 image appered in imgFirst it wont appear in imgSecond.
Is there any way to do that?(dont forget about random)
With Regards
Sreejith
Posted

Create a list of your images. Then, pull your image names from that list, and delete them as you go, so that the list only contains images that have not been used. Or check if there's a random shuffle function you can call on a list and just go in order.
 
Share this answer
 
Alternatively if you want you can maintain a list of images that has already been used. Before assigning the next one, verify that it does not exist in the list i.e. not already been used earlier.
 
Share this answer
 

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