Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 206
  • Last Modified:

Problem using repeater

When I try to display the result of an sql query into a repeater, I get no data. I've tried the query in the analyzer and it works fine. I get no errors from VS. Note for testing purposes the query parameter is now hardcoded.

Imports System.Data.SqlClient
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls

Namespace findandview

    Public Class resultset
        Inherits System.Web.UI.Page

        Protected WithEvents Repeater1 As System.Web.UI.WebControls.Repeater

#Region " Web Form Designer Generated Code "

        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'Put user code to initialize the page here

            'Dim partoftown = Session("partoftown")
            ' Dim partoftown = "kensington"

                Dim conPubs As SqlConnection
                Dim cmdSelect As SqlCommand
                Dim dtrAuthors As SqlDataReader

                ' Retrieve records from database
                conPubs = New SqlConnection("Server=localhost;Trusted_Connection=true;Database=findandview")
                'If partoftown <> "" Then
                'cmdSelect = New SqlCommand("Select description From maintable where area = '" & partoftown & "'", conPubs)
                cmdSelect = New SqlCommand("Select * from maintable where area = 'Kensington'", conPubs)
                dtrAuthors = cmdSelect.ExecuteReader()

                ' Bind to Repeater
                Repeater1.DataSource = dtrAuthors

                'End If

        End Sub

    End Class
End Namespace

in the ASP file:

<asp:repeater id="Repeater1" runat="server">
                              <%# Container.DataItem( "description" ) %>">
  • 2
1 Solution
<asp:Repeater Id="Repeater1" runat="server">
<br />
<%# DataBinder.Eval(Container.DataItem,"description") %>
<br />
Your code means that every odd record will not be shown. So if there is only one record it wont be shown.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now