I’m having a problem displaying an image from an ObjectData Source created by function which adds iems to a list(of T) class. The ObjectData Source then becomes the gridviews Data Soource. All the other fields are displaying, except the image.
Here is my code:
Public Class AutoDealer
Private mLogo As ImageButton
Private mComapnyName As String
Private mAddress As String
Private mContactDetails As String
Public Sub New()
End Sub
Public Sub New(ByVal Logo As ImageButton, ByVal CompanyName As String, ByVal Address As String, ByVal ContactDetails As String)
mLogo = Logo
mComapnyName = CompanyName
mAddress = Address
mContactDetails = ContactDetails
End Sub
Public Property Logo As ImageButton
Get
Return mLogo
End Get
Set(ByVal value As ImageButton)
mLogo = value
End Set
End Property
Public Property CompanyName As String
Get
Return mComapnyName
End Get
Set(ByVal value As String)
mComapnyName = value
End Set
End Property
Public Property Address As String
Get
Return mAddress
End Get
Set(ByVal value As String)
mAddress = value
End Set
End Property
Public Property ContactDetails As String
Get
Return mContactDetails
End Get
Set(ByVal value As String)
mContactDetails = value
End Set
End Property
Public Class DisplayAutodealers
Public Shared Function GetAutodealers() As List(Of AutoDealer)
Dim Connection As SqlConnection = New SqlConnection(...)
Dim Command As SqlCommand = New SqlCommand()
Dim _Reader As SqlDataReader
Command.Connection = Connection
Command.CommandText = "Select ID, Company_Name, Physical_Address, Area_Code, Email_Address, Contact_Number from AutoDealer_Account"
Connection.Open()
_Reader = Command.ExecuteReader
Dim results As New List(Of AutoDealer)
While _Reader.Read()
Dim _AutoDealer As New AutoDealer
Dim AutoDealerID As Integer
AutoDealerID = _Reader(0)
_AutoDealer.Logo.ImageUrl = "GetAutoDealerLogo.aspx?ID=" & AutoDealerID
_AutoDealer.CompanyName = _Reader(1)
_AutoDealer.Address = _Reader(2) & ", " & _Reader(3) & "."
_AutoDealer.ContactDetails = "Phone: " & _Reader(5) & vbCrLf & " or email: " & _Reader(4)
results.Add(_AutoDealer)
End While
Connection.Close()
_Reader.Close()
Return (results)
End Function
My code in my image rendering page (“GetAutoDealerLogo.aspx”) is working. I’ve tested it by displaying images on other pages. This code at the moment is getting a NullReferenceException on the CarImage.ImageUrl = “GetAuctionPageImage.aspx?ID=” & AuctionID line. I’ve tried various ways of getting around this but the image is still not displaying in the gridview.
Any advice would be apprecriated.
Thanks in advance
I think you’d be better off using the Repeater control. That way, you can define the controls and the layout of each record in the bound data source. For your issue, you can add an ASP.NET Image control and bind to that. I was just messing around with the Repeater control for the first time, and I am binding to a List(Of ) in the same way, and it’s a breeze to bind the data, control the layout, etc.