Display .jpg pictures in a datagrid

P

PhotoBug

Need some help, please.

I am trying to get an ASP.Net datagrid to display all jpg pictures that
reside in a folder.
I created a datatable, and added rows for every picture in the folder.
I can get the file name of each picture to display in the grid row cells,
but I would really like the
pictures to display, not the file name. If I get by that problem, I then
need to add a checkbox
to each row, that the web user can click, signifying they want to buy that
picture.

Here is my code that fills the datagrid with the file names of the pictures:

Private Sub GetSmallPics()
Dim PicLocation As String, dir As String
Dim intPics As Integer, I As Integer
Dim workRow As DataRow

Try
PicLocation = VirtualPath & Session("PicLocation")
Dim dirs As String() = Directory.GetFiles(PicLocation, "S_*")
intPics = dirs.Length
For Each dir In dirs
workRow = dt.NewRow()
workRow("objPicture") = dir.ToString
dt.Rows.Add(workRow)
Next
Me.dgSmallThumbs.DataSource = dt
Me.dgSmallThumbs.DataBind()
Catch e As Exception

Me.lblStatus.Text = e.ToString()

End Try

End Sub
 
E

Eliyahu Goldin

Read the file names into an ArrayList. Add to the datagrid a TemplateColumn
with an Image control in it. Databind ImageUrl property to the ArrayList.

Eliyahu
 
P

PhotoBug

I created an ArrayList and read the file names into it.
The ArrayList loaded correctly.
I created a TemplateColumn and added an Image control to the ItemTemplate.

Now, how do I databind the ImageUrl property to the ArrayList using VB code?
After that do I set the datasource of the grid to the ArrayList and then
databind the grid?
Thanks for your help.

New Code: dgSmallThumbs is my datagrid that contains the TemplateColumn.

Private Function LoadPicArray() As Integer
Dim PicLocation As String, dir As String
Try
PicLocation = VirtualPath & Session("PicLocation")
Dim dirs As String() = Directory.GetFiles(PicLocation,
"S_*")
For Each dir In dirs
myAL.Add(dir)
Next
LoadPicArray = myAL.Count



Catch ex As Exception
Me.lblStatus.Text = ex.ToString
End Try
End Function
 
E

Eliyahu Goldin

You don't need VB to setup databinding. In the aspx set datasource of the
grid to the ArrayList instance and
ImageUrl of the image control to "<%# Container.DataItem.Value %>"

Eliyahu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top