Binding results of query to repeater control

G

Guest

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>
 
K

Karl Seguin

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top