Binding results of query to repeater control

Discussion in 'ASP .Net' started by =?Utf-8?B?ZGluZXNo?=, May 10, 2005.

  1. After a selection a selection is made, the form posts to the server, but no
    data gets displayed in the repeater. no errors are given.

    <form id="Form1" runat="server">
    Category:
    <asp:dropdownlist id="category" runat="server"
    autoPostBack="True">
    <asp:ListItem Text="" />
    <asp:ListItem Text="Barbera" />
    ...
    <asp:dropdownlist id="region" runat="server">
    <asp:ListItem Text="" />
    <asp:ListItem Text="Aconcagua" />
    ....

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

    If Not IsPostBack Then
    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=winestore")
    If color.SelectedItem.Text <> "" Then
    cmdSelect = New SqlCommand("Select * From maintable
    where color=" & color.SelectedItem.Text, conPubs)
    conPubs.Open()
    dtrAuthors = cmdSelect.ExecuteReader()

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

    dtrAuthors.Close()
    conPubs.Close()

    ElseIf category.SelectedItem.Text <> "" Then
    cmdSelect = New SqlCommand("Select * From maintable
    where category=" & category.SelectedItem.Text, conPubs)
    conPubs.Open()
    dtrAuthors = cmdSelect.ExecuteReader()

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

    dtrAuthors.Close()
    conPubs.Close()
    ....
    (repeated for each data element)

    <asp:repeater id="Repeater1" runat="server">

    <ItemTemplate>
    <%# Container.DataItem( "title" ) %>
    </ItemTemplate>


    </asp:repeater></p>
     
    =?Utf-8?B?ZGluZXNo?=, May 10, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?ZGluZXNo?=

    Karl Seguin Guest

    Dinesh:
    Your code is wrapped in a If Not Page.IsPostback...however, as you say, the
    form IS posting back (which it should).

    One solution would be to remove the NOT from the if statement.

    A BETTER solution would be to place this code in the SelectedIndexChanged
    event of the dropdownlist...

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
    http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    come!)


    "dinesh" <> wrote in message
    news:...
    > After a selection a selection is made, the form posts to the server, but
    > no
    > data gets displayed in the repeater. no errors are given.
    >
    > <form id="Form1" runat="server">
    > Category:
    > <asp:dropdownlist id="category" runat="server"
    > autoPostBack="True">
    > <asp:ListItem Text="" />
    > <asp:ListItem Text="Barbera" />
    > ...
    > <asp:dropdownlist id="region" runat="server">
    > <asp:ListItem Text="" />
    > <asp:ListItem Text="Aconcagua" />
    > ...
    >
    > Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    > Handles MyBase.Load
    > ' Put user code to initialize the page here
    >
    > If Not IsPostBack Then
    > 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=winestore")
    > If color.SelectedItem.Text <> "" Then
    > cmdSelect = New SqlCommand("Select * From maintable
    > where color=" & color.SelectedItem.Text, conPubs)
    > conPubs.Open()
    > dtrAuthors = cmdSelect.ExecuteReader()
    >
    > ' Bind to Repeater
    > Repeater1.DataSource = dtrAuthors
    > Repeater1.DataBind()
    >
    > dtrAuthors.Close()
    > conPubs.Close()
    >
    > ElseIf category.SelectedItem.Text <> "" Then
    > cmdSelect = New SqlCommand("Select * From maintable
    > where category=" & category.SelectedItem.Text, conPubs)
    > conPubs.Open()
    > dtrAuthors = cmdSelect.ExecuteReader()
    >
    > ' Bind to Repeater
    > Repeater1.DataSource = dtrAuthors
    > Repeater1.DataBind()
    >
    > dtrAuthors.Close()
    > conPubs.Close()
    > ...
    > (repeated for each data element)
    >
    > <asp:repeater id="Repeater1" runat="server">
    >
    > <ItemTemplate>
    > <%# Container.DataItem( "title" ) %>
    > </ItemTemplate>
    >
    >
    > </asp:repeater></p>
    >
     
    Karl Seguin, May 10, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Donald Williamson

    Repeater Control Binding question

    Donald Williamson, Nov 14, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    616
    Guest
    Nov 19, 2003
  2. MeiMei
    Replies:
    0
    Views:
    617
    MeiMei
    Jan 20, 2004
  3. Abhishek Srivastava

    Binding a Repeater control to an ArrayList of objects

    Abhishek Srivastava, Feb 5, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    6,523
    Abhishek Srivastava
    Feb 5, 2004
  4. Eric Nelson
    Replies:
    5
    Views:
    1,574
    Alexey Smirnov
    Feb 4, 2009
  5. MeiMei

    binding user control to Repeater web control

    MeiMei, Jan 19, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    146
    MeiMei
    Jan 19, 2004
Loading...

Share This Page