Question : asp.net: How to bind Images to a ListView from a Database - I have a special need! the Image have already be downloaded

I have download the images and have pointed them to my LISTVIEW see code in code block. also see my screenshot of my layout of the pictures. Since the Images have been downloaded from the database, I need to build a rountine that will bind the picture to the ItemTemplate.

The ImageID, EquipmentID, MimeType & ImageData have already been SQL (Selected & download) from the database & pointed to the listview ItemTemplate with the record values require to bind the image to the ItemTemplate. I believe all that is need is an HTTP reading of MimeType & ImageData. I dont know how code it todo that.......
 ------------------------------------------------------------------------------
Get......ContentType = imagereader["MIMEType"].ToString ();
Get......BinaryWrite(imagereader["ImageData"]);
 ------------------------------------------------------------------------------
<asp:Image ID="Image10" runat="server" Height="100px"
                ImageUrl='<%# DisplayImage(Eval("ImageData1")) %>' GenerateEmptyAlternateText="True" Visible='<%# ShowImg(Eval("ImageData1")) %>' />

I need a function that will bind the image  . --> DisplayImage
----------------------------------------------------------------------------------------------------
Below is the function that returned the values from the DB and Arrange them in the select statement to way I want the images displayed. This is working... what I do not know is how to Bind or Eval the values to the ItemTemplate...
-----------------------------------------------------------------------------------------------
GetCustomerImage
(
     @ImageCount integer,
     @EquipId uniqueidentifier
)
RETURNS TABLE
AS
RETURN
(
SELECT ImageID, EquipmentID, Title, ImageData, MIMEType FROM (
  SELECT
    ROW_NUMBER() OVER (ORDER BY ImageId ASC) AS rownumber,
    *
  FROM CustomerImages Where EquipmentId = @EquipId) AS foo
  WHERE rownumber = @ImageCount)

-----------------------------------------------------------------------------------------------
CustomerImages Table

ImageID             uniqueidentifier
EquipmentID      uniqueidentifier
Title                    varchar(50)
ImageData         varbinary(MAX)
MIMEType           varchar(50)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
<%@ Page Language="VB" MasterPageFile="~/Nested Master Pages/annonymous.master" Title="Untitled Page" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.IO" %>

<script runat="server">
    
    Dim intGlobal As Integer = 0
    Dim currentUser As MembershipUser = Membership.GetUser()
    Sub Page_Init()
        intGlobal = intGlobal + 1
        ErrorMessage.Text += "<br>Page_Init has called this line at " & Now() & _
                                  " with the value of intGlobal being :" & intGlobal
    End Sub
  
    Public Sub Page_Load() Handles Me.Load
        
        Dim currentUser As MembershipUser = Membership.GetUser()
        'indexpagedatasource2.SelectParameters["EquipmentID"].DefaultValue = indexpagedatasource.SelectParameters["EquipmentID"].ToString();
    
    End Sub
    
    Protected Sub indexpagedatasource_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs)
     
        ' Get a reference to the currently logged on user
        Dim currentUser As MembershipUser = Membership.GetUser()
        ' Determine the currently logged on user's UserId value

        Dim currentUserId As Guid = CType(currentUser.ProviderUserKey, Guid)
        
        ' Assign the currently logged on user's UserId to the @UserId parameter
        e.Command.Parameters("EquipmentID").Value = currentUserId.ToString()
      
    End Sub
    
    'Protected Sub indexpagedatasource2_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs)
     
    ' Get a reference to the currently logged on user
    ''Dim currentUser As MembershipUser = Membership.GetUser()
    ' Determine the currently logged on user's UserId value
    ''Dim currentUserId As Guid = CType(currentUser.ProviderUserKey, Guid)
        
    'indexpagedatasource2.SelectParameters["EquipmentID"].DefaultValue = indexpagedatasource.SelectParameters["EquipmentID"].ToString()
        
    '' indexpagedatasource2.SelectParameters("EquipmentID").DefaultValue = ListView1.SelectedValue.ToString() 'ListView1.DataKeys(ListView1.SelectedIndex).Value.ToString()
    ''End Sub
    
    Public Function ShowImg(ByVal obj As Object) As Boolean
        If IsDBNull(obj) Then
            ' Do the processing here...
            ShowImg = False
        Else
            ShowImg = True
        End If
        
    End Function
    
    'Welcome: <b><%=currentUser.UserName%></b>.<br />
    'EquipmentId: <b><%=Equipment%></b>
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <asp:Label ID="ErrorMessage" runat="server" EnableViewState="False" Visible="False"></asp:Label>
    
    <asp:SqlDataSource ID="indexpagedatasource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:Index2PageDataSource %>" 
        
        SelectCommand="SELECT TOP (100) PERCENT E.Year, E.Make, E.Model, E.Type, E.MilesHours, E.VinSerial, E.Description, E.Location, E.Price, E.SignUpDate, 
                      UserProfile.Name, UserProfile.Company, UserProfile.Phone, UserProfile.WebsiteURL, UserProfile.Email, E.EquipmentID, 
                      GetCustomerImage_1.ImageID AS ImageID1, GetCustomerImage_1.EquipmentID AS EquipmentID1, GetCustomerImage_1.Title AS Title1, GetCustomerImage_1.ImageData AS ImageData1, GetCustomerImage_1.MIMEType AS MIMEType1,
                      GetCustomerImage_2.ImageID AS ImageID2, GetCustomerImage_2.EquipmentID AS EquipmentID2, GetCustomerImage_2.Title AS Title2, GetCustomerImage_2.ImageData AS ImageData2, GetCustomerImage_2.MIMEType AS MIMEType2,
                      GetCustomerImage_3.ImageID AS ImageID3, GetCustomerImage_3.EquipmentID AS EquipmentID3, GetCustomerImage_3.Title AS Title3, GetCustomerImage_3.ImageData AS ImageData3, GetCustomerImage_3.MIMEType AS MIMEType3, 
                      GetCustomerImage_4.ImageID AS ImageID4, GetCustomerImage_4.EquipmentID AS EquipmentID4, GetCustomerImage_4.Title AS Title4, GetCustomerImage_4.ImageData AS ImageData4, GetCustomerImage_4.MIMEType AS MIMEType4,
                      GetCustomerImage_5.ImageID AS ImageID5, GetCustomerImage_5.EquipmentID AS EquipmentID5, GetCustomerImage_5.Title AS Title5, GetCustomerImage_5.ImageData AS ImageData5, GetCustomerImage_5.MIMEType AS MIMEType5, 
                      GetCustomerImage_6.ImageID AS ImageID6, GetCustomerImage_6.EquipmentID AS EquipmentID6, GetCustomerImage_6.Title AS Title6, GetCustomerImage_6.ImageData AS ImageData6, GetCustomerImage_6.MIMEType AS MIMEType6
                      
                      FROM Equipment AS E INNER JOIN
                      UserProfile ON E.UserId = UserProfile.UserId
                      OUTER APPLY GetCustomerImage(1, E.EquipmentID) AS GetCustomerImage_1 
                      OUTER APPLY GetCustomerImage(2, E.EquipmentID) AS GetCustomerImage_2 
                      OUTER APPLY GetCustomerImage(3, E.EquipmentID) AS GetCustomerImage_3
                      OUTER APPLY GetCustomerImage(4, E.EquipmentID) AS GetCustomerImage_4
                      OUTER APPLY GetCustomerImage(5, E.EquipmentID) AS GetCustomerImage_5
                      OUTER APPLY GetCustomerImage(6, E.EquipmentID) AS GetCustomerImage_6 
                      
                      GROUP BY E.Year, E.Make, E.Model, E.Type, E.MilesHours, E.VinSerial, E.Description, E.Location, E.Price, E.SignUpDate, dbo.UserProfile.Name, 
                      UserProfile.Company, UserProfile.Phone, UserProfile.WebsiteURL, UserProfile.Email, E.EquipmentID, 
                      GetCustomerImage_1.ImageID, GetCustomerImage_1.EquipmentID, GetCustomerImage_1.Title, GetCustomerImage_1.ImageData, GetCustomerImage_1.MIMEType,   
                      GetCustomerImage_2.ImageID, GetCustomerImage_2.EquipmentID, GetCustomerImage_2.Title, GetCustomerImage_2.ImageData, GetCustomerImage_2.MIMEType, 
                      GetCustomerImage_3.ImageID, GetCustomerImage_3.EquipmentID, GetCustomerImage_3.Title, GetCustomerImage_3.ImageData, GetCustomerImage_3.MIMEType,
                      GetCustomerImage_4.ImageID, GetCustomerImage_4.EquipmentID, GetCustomerImage_4.Title, GetCustomerImage_4.ImageData, GetCustomerImage_4.MIMEType, 
                      GetCustomerImage_5.ImageID, GetCustomerImage_5.EquipmentID, GetCustomerImage_5.Title, GetCustomerImage_5.ImageData, GetCustomerImage_5.MIMEType, 
                      GetCustomerImage_6.ImageID, GetCustomerImage_6.EquipmentID, GetCustomerImage_6.Title, GetCustomerImage_6.ImageData, GetCustomerImage_6.MIMEType
                      
ORDER BY E.SignUpDate DESC" >  
    </asp:SqlDataSource>
    
    <asp:ListView ID="ListView1" runat="server" DataKeyNames="EquipmentID" DataSourceID="indexpagedatasource">
           <LayoutTemplate>
                <asp:Placeholder runat="server" ID="itemPlaceholder"></asp:Placeholder>                           
                <br />
                <br />                                    
           </LayoutTemplate>       
        <ItemTemplate>
             
            <asp:Label ID="YearLabel" runat="server" Font-Names="Arial" Font-Size="Small" 
                Text='<%# Eval("Year") %>' Font-Bold="True"></asp:Label>
            <asp:Label ID="MakeLabel" runat="server" Font-Names="Arial" Font-Size="Small" 
                Text='<%# Eval("Make") %>' Font-Bold="True"></asp:Label>
            <asp:Label ID="ModelLabel" runat="server" Font-Names="Arial" Font-Size="Small" 
                Text='<%# Eval("Model") %>' Font-Bold="True"></asp:Label>
            <asp:Label ID="TypeLabel" runat="server" Font-Names="Arial" Font-Size="Small" 
                Text='<%# Eval("Type") %>' Font-Bold="True"></asp:Label>
            &nbsp;-
            <span><asp:Label ID="PriceLabel" runat="server" 
                Font-Names="Arial" Font-Size="Small" 
                Text='<%# Eval("Price") %>' Font-Bold="True"></asp:Label>
            </span>
            <br />
            <span style="font-family:Arial; font-size:small">Miles / Hours:</span>
            <asp:Label ID="MilesHoursLabel" runat="server" Font-Names="Arial" 
                Font-Size="Small" Text='<%# Eval("MilesHours") %>'></asp:Label>
            <br />
            <span style="font-family:Arial; font-size:small">VIN / Serial No:</span>
            <asp:Label ID="VinSerialLabel" runat="server" Font-Names="Arial" 
                Font-Size="Small" Text='<%# Eval("VinSerial") %>'></asp:Label>
            <br />
            <span style="font-family:Arial; font-size:small">Description:</span>&nbsp;
            <asp:Label ID="DescriptionLabel" runat="server" Font-Names="Arial" 
                Font-Size="Small" Text='<%# Eval("Description") %>'></asp:Label>
            <br />
            <span style="font-family:Arial; font-size:small">Location:</span>&nbsp
            <asp:Label ID="LocationLabel" runat="server" Font-Names="Arial" 
                Font-Size="Small" Text='<%# Eval("Location") %>'></asp:Label>
            <br />
            <span style="font-family:Arial; font-size:small;font-weight:bold">For more info contact:</span> 
            <asp:Label ID="NameLabel" runat="server" Font-Names="Arial" Font-Size="Small" 
                Font-Bold="True" Text='<%# Eval("Name") %>'></asp:Label>
               &nbsp;-
               <asp:Label ID="PhoneLabel" runat="server" Font-Names="Arial" Font-Size="Small" 
                Font-Bold="True" Text='<%# Eval("Phone") %>'></asp:Label>
                <br />
                <asp:HyperLink ID="Email" runat="server" Font-Names="Arial" 
                Font-Size="Small" NavigateURL='<%# Eval("Email") %>' 
                Text='<%# Eval("Email") %>'></asp:HyperLink>
                    <br />
                <asp:HyperLink ID="WebsiteURL" runat="server" Font-Names="Arial" 
                    Font-Size="Small" NavigateURL='<%# Eval("WebsiteURL") %>' 
                Text='<%# Eval("WebsiteURL") %>'></asp:HyperLink>
                    <br />   
                 <asp:Label ID="SignUpDate" runat="server" Font-Names="arial" 
                Font-Size="Smaller" Text='<%# Eval("SignUpDate", "{0:d}") %>'></asp:Label>
                    <br /> 
                    
                <asp:Image ID="Image10" runat="server" Height="100px" 
                ImageUrl='<%# Eval("ImageData1") %>' GenerateEmptyAlternateText="True" Visible='<%# ShowImg(Eval("ImageData1")) %>' />
                <asp:Image ID="Image20" runat="server" Height="100px" 
                ImageUrl='<%# Eval("ImageData2") %>' GenerateEmptyAlternateText="True" Visible='<%# ShowImg(Eval("ImageData2")) %>' />
                <asp:Image ID="Image30" runat="server" Height="100px" 
                ImageUrl='<%# Eval("ImageData3") %>' GenerateEmptyAlternateText="True" Visible='<%# ShowImg(Eval("ImageData3")) %>' />
                <asp:Image ID="Image40" runat="server" Height="100px" 
                ImageUrl='<%# Eval("ImageData4") %>' GenerateEmptyAlternateText="True" Visible='<%# ShowImg(Eval("ImageData4")) %>' />
                <asp:Image ID="Image50" runat="server" Height="100px" 
                ImageUrl='<%# Eval("ImageData5") %>' GenerateEmptyAlternateText="True" Visible='<%# ShowImg(Eval("ImageData5")) %>' />
                <asp:Image ID="Image60" runat="server" Height="100px" 
                ImageUrl='<%# Eval("ImageData6") %>' GenerateEmptyAlternateText="True" Visible='<%# ShowImg(Eval("ImageData6")) %>' /> 
      
        </ItemTemplate>  
        <ItemSeparatorTemplate>
        <hr />
        <br />
        </ItemSeparatorTemplate>   
     </asp:ListView>
    
     <asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1" 
        PageSize="5">
        <Fields>
            <asp:NextPreviousPagerField PreviousPageText="&lt;" ShowFirstPageButton="true"
                ShowNextPageButton="False" />
            <asp:NumericPagerField />
            <asp:NextPreviousPagerField NextPageText="&gt;" ShowLastPageButton="True" 
                ShowPreviousPageButton="False" />
        </Fields>
      </asp:DataPager>
</asp:Content>
Attachments:
 
Layout of Picture in a List View
Layout of Picture in a List View
 

Answer : asp.net: How to bind Images to a ListView from a Database - I have a special need! the Image have already be downloaded

try

<img src='<%# "ShowImage.ashx?id=" + Eval("ImageData1") %>' border=1>
Also try a hardcoded value like
<img src="ShowImage.ashx?id=123" border=1>
replace 123 with a correct id value for the image

Also you could try this control

http://www.codeproject.com/KB/custom-controls/RbmImageControl.aspx

Random Solutions  
 
programming4us programming4us