So i have a database in sql server 2008 and in 1 table i have information with a picture in it, i can retrieve 1 picture from the DB to display in a picturebox, wat i want to do now is read all the pictures and disply them all at once in different pictureboxes so when you click on a picturebox information is displayed on the side in lables about that picture.

Click Here here is a image of how the forum looks

I really have no idea how i can do this and if someone has a better idea plz share with me also remeber the picture is in the same table as the information about the picture should i put it in seperate table if i want to display all the pictures


Edited 4 Years Ago by tieties

If you name your picture boxes in such a way that it ends with a number from 0 to whatever, all you have to do is iterate through the rows in the table and assign each image to the pictureboxes.
Something like this:

Dim img As BitMap
Dim picboxIndex As Integer = 0
For Each row As DataRow In dt.Rows
    Dim mem As New IO.MemoryStream(CType(row("image field"), Byte()))
    img = Image.FromStream(mem)
    DirectCast(Me.FindControl("picBox" + picboxIndex), PictureBox).Image = img
    picboxIndex += 1

Once you have the pictureboxes loaded with the images, check out this post. TnTinMN's answer contains a very easy to understand sample on how to handle the click event of an array of controls. One routine to control them all lol

As for displaying the info for the images, pull that at the same time you pull the image and save it in a variable, maybe a list. From there the index of the image will equal the index of the info.

Edited 4 Years Ago by tinstaafl

This article has been dead for over six months. Start a new discussion instead.