954,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

not displaying the first image from the database

Hi i have a very strange bug in my code somewhere. it is stopping the first image being displayed.

i only noticed it just now and don't have the knowledge on how to fix it.

it seems that the code in default2.aspx misses the first image tag and request on line 41 but applies it to line 49.

what should happen is that it displays two identical images as specified by the querystring

any help will be most welcomed.

1    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="viewdetails.aspx.vb" Inherits="viewdetails" %>
2    
3    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4    
5    <html xmlns="http://www.w3.org/1999/xhtml">
6    <head runat="server">
7        <title>Untitled Page</title>
8    </head>
9    <body>
10       <form id="form1" runat="server">
11       <div>
12       
13           <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
14               ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
15               SelectCommand="SELECT * FROM [PropertyView] WHERE ([PropertyID] = @PropertyID)">
16               <SelectParameters>
17                   <asp:QueryStringParameter Name="PropertyID" QueryStringField="PropertyID" 
18                       Type="Int32" />
19               </SelectParameters>
20           </asp:SqlDataSource>
21           
22           
23       
24           <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
25               DataKeyNames="PropertyID" DataSourceID="SqlDataSource1">
26               <Columns>
27                   <asp:BoundField DataField="PropertyTitle" HeaderText="PropertyTitle" 
28                       SortExpression="PropertyTitle" />
29                   <asp:BoundField DataField="PropertyType" HeaderText="PropertyType" 
30                       SortExpression="PropertyType" />
31                   <asp:BoundField DataField="PropertyPrice" HeaderText="PropertyPrice" 
32                       SortExpression="PropertyPrice" />
33                   <asp:BoundField DataField="PropertyBedroom" HeaderText="PropertyBedroom" 
34                       SortExpression="PropertyBedroom" />
35                   <asp:BoundField DataField="PropertyDescription" 
36                       HeaderText="PropertyDescription" SortExpression="PropertyDescription" />
37                   <asp:BoundField DataField="PropertyLocation" HeaderText="PropertyLocation" 
38                       SortExpression="PropertyLocation" />
39                       <asp:TemplateField>
40                           <ItemTemplate>
41                               <asp:Image ID="Image1" runat="server" 
42                                   ImageUrl='<%# Eval("PropertyID", "Default2.aspx?PropertyID={0}") %>' />
43                           </ItemTemplate>
44                   </asp:TemplateField>
45               </Columns>
46           </asp:GridView>
47       
48           
49           <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
50           <ItemTemplate>
51           <asp:Image ID="Image1" runat="server" 
52                                   ImageUrl='<%# Eval("PropertyID", "Default2.aspx?PropertyID={0}") %>' />
53           </ItemTemplate>
54           </asp:Repeater>
55       
56       </div>
57       </form>
58   </body>
59   </html>
60

here is the code from default2.aspx.vb the connects to the database and assigns the image based on the productid

1    Imports System.Data.SqlClient
2    Partial Class Default2
3        Inherits System.Web.UI.Page
4        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
5            Dim PropertyID As Integer = Convert.ToInt32(Request.QueryString("PropertyID"))
6    
7            'Connect to the database and bring back the image contents & MIME type for the specified picture
8            Using myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
9    
10               Const SQL As String = "SELECT [MIMEType], [ImageData] FROM [Property] WHERE [PropertyID] = @PropertyID"
11               Dim myCommand As New SqlCommand(SQL, myConnection)
12               myCommand.Parameters.AddWithValue("@PropertyID", PropertyID)
13   
14               myConnection.Open()
15               Dim myReader As SqlDataReader = myCommand.ExecuteReader
16   
17               If myReader.Read Then
18                   Response.ContentType = myReader("MIMEType").ToString()
19                   Response.BinaryWrite(myReader("ImageData"))
20               End If
21   
22               myReader.Close()
23               myConnection.Close()
24           End Using
25       End Sub
26   End Class
27
adamjw3
Newbie Poster
5 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

Post in ASP.NET Section
Click Here to Go there.

Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You