Display .jpg pictures in a datagrid

Discussion in 'ASP .Net Datagrid Control' started by PhotoBug, Jun 30, 2004.

  1. PhotoBug

    PhotoBug Guest

    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
    PhotoBug, Jun 30, 2004
    #1
    1. Advertising

  2. 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

    "PhotoBug" <> wrote in message
    news:40e23d88$0$16466$...
    > 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
    >
    >
    Eliyahu Goldin, Jun 30, 2004
    #2
    1. Advertising

  3. PhotoBug

    PhotoBug Guest

    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



    "Eliyahu Goldin" <> wrote in message
    news:...
    > 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
    >
    > "PhotoBug" <> wrote in message
    > news:40e23d88$0$16466$...
    > > 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
    > >
    > >

    >
    >
    PhotoBug, Jul 1, 2004
    #3
  4. 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

    "PhotoBug" <> wrote in message
    news:40e383d2$0$16504$...
    > 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
    >
    >
    >
    > "Eliyahu Goldin" <> wrote in message
    > news:...
    > > 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
    > >
    > > "PhotoBug" <> wrote in message
    > > news:40e23d88$0$16466$...
    > > > 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
    > > >
    > > >

    > >
    > >

    >
    >
    Eliyahu Goldin, Jul 1, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roland
    Replies:
    0
    Views:
    1,041
    Roland
    May 12, 2004
  2. Matthias
    Replies:
    5
    Views:
    410
    Whitecrest
    Jun 1, 2004
  3. OK
    Replies:
    9
    Views:
    428
    Eliyahu Goldin
    Mar 30, 2008
  4. Martin Raychev
    Replies:
    1
    Views:
    271
    Alvin Bruney [MVP]
    Mar 2, 2004
  5. Yannick

    ASP changes Big JPG -> Small JPG

    Yannick, Feb 2, 2004, in forum: ASP General
    Replies:
    6
    Views:
    145
    Tim Williams
    Feb 3, 2004
Loading...

Share This Page