473,473 Members | 1,833 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Binding results of query to repeater control

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>

Nov 19 '05 #1
1 1247
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" <di****@discussions.microsoft.com> wrote in message
news:17**********************************@microsof t.com...
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>

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Gastin | last post by:
I am digesting a web serivce from Amazon.Com. I have the following class which was autogenerated by VS.NET when I created a Web Reference to...
0
by: Jim French | last post by:
I have a page that takes a comma delimited string and needs to bind to a Repeater control. The string is split into an Array, and each value is put into a DataBase query via a For Each loop. The...
2
by: Donald Williamson | last post by:
I have a DataReader that I am binding to a Repeater control. In the DataReader, I have two fields: 'Name1' and 'Name2' 'Name1' will always have a person's name. Name2 periodically has a person's...
2
by: Kristoffer Arfvidson | last post by:
How, do I bind a database to either a Datagrid or a repeater (via PagedDataSource)?? Im, trying everything, but I simply cant get it... I use RS.GetRows to get all the info at once from the...
2
by: Gastin | last post by:
I am consuming a web serivce from Amazon.Com. I have the following class which was autogenerated by VS.NET when I created a Web Reference to...
9
by: Jaybuffet | last post by:
my aspx has something like this <asp:Repeater id="Repeater1" runat="server"> <ItemTemplate> <mycontrol:ctl id="ctlId" obj='<%# Container.DataItem %>' showItem="true"/> </ItemTemplate>...
5
by: Brad Baker | last post by:
I'm completely new to ASP.NET programming, so please accept my apologies in advance for asking what is probably an obvious question. :-) I'm trying to write a page which will display the...
4
by: Brad Baker | last post by:
I'm going a little crazy :) I'm trying to bind a repeater control to a dataset on page load using the following code: if (Request.QueryString != null) { string customerid = Request.QueryString;...
0
by: | last post by:
I have a question about spawning and displaying subordinate list controls within a list control. I'm also interested in feedback about the design of my search application. Lots of code is at the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.