none
Displaying Single Product Image in Repeater Control from 3 pictures Asp.NET

    Question

  • I have developed a Real Estate website in which user can buy and sell their properties. I used Repeater control to display the images and other related fields. The problem is that one Property can have multiple images what <g class="gr_ gr_15 gr-alert gr_tiny gr_spell gr_disable_anim_appear ContextualSpelling multiReplace" data-gr-id="15" id="15">i</g> want is to show the first image of the property in Repeater Control is it possible to choose the first picture of the product from the database?

    Note: I am using VB.NET

    This is the code:

    Private Sub Rent_Load(sender As Object, e As EventArgs) Handles Me.Load
    Dim cn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("MyConn").ToString)
        Dim da As SqlDataAdapter
        If cn.State = ConnectionState.Closed Then
            cn.Open()
    
    Dim query As String = "Select PD.P_ID, PD.currency, PD.Price, PT.P_Type, 
    PA.Location, PF.Unit, PF.Land_Area, PF.No_Bedrooms, PF.No_Bathrooms, 
    PP.Purpose_Type, PPIC.P_Photo FROM Property_Details as PD INNER JOIN 
    Property_Type as PT ON  PD.T_ID = PT.T_ID INNER JOIN Property_Address AS PA 
    ON PD.P_ID = PA.P_ID    INNER JOIN Property_Features AS PF ON PF.P_ID = 
    PD.P_ID INNER JOIN Property_Purpose AS PP ON PP.PP_ID = PD.PP_ID INNER JOIN 
    Property_Photos AS PPIC ON PD.P_ID = PPIC.[P_ID] WHERE Purpose_Type='Rent'     
    AND IsPublished='True' AND Property_Status='Open' ORDER By P_ID DESC"
    
            da = New SqlDataAdapter(query, cn)
            dt = New DataTable
            da.Fill(dt)
            RentRepeater.DataSource = dt
            RentRepeater.DataBind()
        End If
    End Sub

    Is it possible optimize the query and get the proper result.</g>

    Property Result ScreenshotThanks,


    Tuesday, April 04, 2017 6:33 AM

Answers

  • Seems that the problem can be solved on SQL level. One of the solutions is to remove INNER JOIN Property_Photos AS PPIC ON PD.P_ID = PPIC.[P_ID], then change PPIC.P_Photo to the highlighted part:

    SELECT PD.P_ID, …, PP.Purpose_Type, (SELECT TOP(1) PPIC.P_Photo FROM Property_Photos AS PPIC WHERE PPIC.P_ID = PD.P_ID) AS P_Photo FROM Property_Details AS PD …

    If possible, perform some manual queries to check the results.

    • Marked as answer by Naveed Karimi Tuesday, April 04, 2017 8:38 AM
    Tuesday, April 04, 2017 7:49 AM

All replies

  • Your problem is a presentation problem, not really a VB problem. 

    Try for that the Microsoft ASP.Net forums

    http://forums.asp.net


    Success
    Cor

    Tuesday, April 04, 2017 7:21 AM
  • I am using ASP.net (VB.NET) to present the property in repeater control.

    Tuesday, April 04, 2017 7:26 AM
  • Seems that the problem can be solved on SQL level. One of the solutions is to remove INNER JOIN Property_Photos AS PPIC ON PD.P_ID = PPIC.[P_ID], then change PPIC.P_Photo to the highlighted part:

    SELECT PD.P_ID, …, PP.Purpose_Type, (SELECT TOP(1) PPIC.P_Photo FROM Property_Photos AS PPIC WHERE PPIC.P_ID = PD.P_ID) AS P_Photo FROM Property_Details AS PD …

    If possible, perform some manual queries to check the results.

    • Marked as answer by Naveed Karimi Tuesday, April 04, 2017 8:38 AM
    Tuesday, April 04, 2017 7:49 AM
  • Thank you very much i really appreciate your answer i was searching for the solution since few days.

    Tuesday, April 04, 2017 8:39 AM