Learn how to a build a cloud-first strategyRegister Now

x
  • 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)
                conPubs.Open()
                dtrAuthors = cmdSelect.ExecuteReader()

                ' Bind to Repeater
                Repeater1.DataSource = dtrAuthors
                Repeater1.DataBind()

                dtrAuthors.Close()
                conPubs.Close()
                'End If



        End Sub

    End Class
End Namespace

--------
in the ASP file:


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

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