Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Binding results of query to repeater control

Reply
Thread Tools

Binding results of query to repeater control

 
 
=?Utf-8?B?ZGluZXNo?=
Guest
Posts: n/a
 
      05-09-2005
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>

 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      05-10-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET won't retrieve query results that depend on union query Eric Nelson ASP .Net 5 02-04-2009 10:51 PM
Binding a Repeater control to an ArrayList of objects Abhishek Srivastava ASP .Net 2 02-05-2004 02:44 PM
binding user control to repeater web control MeiMei ASP .Net 0 01-20-2004 12:00 AM
binding user control to Repeater web control MeiMei ASP .Net Datagrid Control 0 01-19-2004 11:59 PM
Repeater Control Binding question Donald Williamson ASP .Net 2 11-19-2003 05:27 PM



Advertisments