Problem with Datagrid ItemDatabound !!!!

M

Michael Persaud

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
 

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,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top