Home > ASP.Net > How to Check ImageURL in DataList

How to Check ImageURL in DataList


try this example that we store image name in database and uplaod image in Car_Image folder

Place this function in page code behind:
    Protected Function GetImageUrl(ByVal url As Object) As String
        Dim url1 As String = ""
        If url Is DBNull.Value OrElse String.IsNullOrEmpty(url) Then
            url1 = "~/Car_Image/NOIMAGE.jpg"
            url1 = String.Format("~/Car_Image/{0}", url)
        End If

        Return ResolveUrl(url1)
    End Function

And change the image code to :

<asp: DataList ID="dlCountry" runat="server"  RepeatDirection="Horizontal" >
<asp:image id="Image1" runat="server" ImageUrl='<%# GetImageUrl(Eval("Image")) %>' />
</asp: DataList>

Good Luck

Categories: ASP.Net
  1. November 19, 2012 at 5:23 am

    This is a very good tip particularly to those fresh to the blogosphere.
    Simple but very accurate info… Thank you for sharing this one.
    A must read article!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: