Problem with Datagrid ItemDatabound !!!!

Discussion in 'ASP .Net Web Controls' started by Michael Persaud, Jul 14, 2004.

  1. Hi All,

    Can someone please show me where i am wrong

    I am tring to have the path (from sql) of images to be bound to their
    picture box.

    So far i am getting the last record from the DB being placed in all the
    images and not thier respective records.

    The idea was to loop through the datagrid souce table and then do a look up
    and load the images


    PLEASE ANY HELP WOULD BE APPRECIATED

    Thanks
    MP


    Sub DataGridProduct_ItemDataBound(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.DataGridItemEventArgs) Handles
    DataGridProduct.ItemDataBound

    GetImageRowsX(e)
    End Sub

    Sub GetImageRowsX(ByVal e) ' As
    System.Web.UI.WebControls.DataGridItemEventArgs) Handles
    DataGridProduct.ItemDataBound
    dgSource = DataGridProduct.DataSource
    Dim catid, i, cCount As Integer
    Dim ImagePath As String
    cCount = dgSource.tables(0).rows.count
    Dim nIndx As Integer
    Label1.Text = ""
    Dim dr As SqlDataReader
    Dim img As New Image

    For i = 0 To cCount - 1
    nIndx = i
    catid = dgSource.tables(0).rows(nIndx)(0)

    ImagePath = ""

    Dim cmd As New SqlCommand _
    ("select categoryid,path from categories where categoryid = " &
    catid, SQLCATCON)
    SQLCATCON.Close()
    SQLCATCON.Open()
    dr = cmd.ExecuteReader()
    dr.Read()
    If Not dr.GetValue(1) Is DBNull.Value Then
    ImagePath = dr.GetValue(1)

    If e.Item.ItemType = ListItemType.AlternatingItem Or
    e.Item.ItemType = ListItemType.Item Then
    'img = CType(e.Item.Cells(2).Controls(1),
    System.Web.UI.WebControls.Image)
    img = CType(e.Item.Cells(2).FindControl("ImageBox"),
    System.Web.UI.WebControls.Image)
    img.ImageUrl = "images/" + ImagePath
    e.Item.Cells(2).Controls.Add(img)
    img.ToolTip = e.Item.Cells(1).Text
    Else

    End If
    End If
    dr.Close()
    'Label1.Text = Label1.Text + catid.ToString + ImagePath
    Next

    End Sub
     
    Michael Persaud, Jul 14, 2004
    #1
    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. Tony Middleton

    Datagrid losing changes made in ItemDataBound

    Tony Middleton, Apr 22, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    307
    Tony Middleton
    Apr 22, 2004
  2. =?iso-8859-1?Q?Andr=E9_Almeida_Maldonado?=

    DataGrid - ItemDataBound

    =?iso-8859-1?Q?Andr=E9_Almeida_Maldonado?=, Jul 6, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,032
    Ken Cox [Microsoft MVP]
    Jul 7, 2004
  3. Dave

    ItemDataBound event of DataGrid

    Dave, Oct 7, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,962
    Scott Allen
    Oct 7, 2004
  4. RJN
    Replies:
    1
    Views:
    534
    Brent Humber
    Dec 24, 2006
  5. =?Utf-8?B?Sm9u?=

    DataGrid, ItemDataBound

    =?Utf-8?B?Sm9u?=, Jan 13, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    515
    Eliyahu Goldin
    Jan 13, 2005
Loading...

Share This Page