473,386 Members | 1,835 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Linking 2 Drop Downs and Repeater Control

I am having trouble trying to link 2 drop down lists and
a repeater control. What i want is 2 drop down lists, the
first being a list of food categories. When a category is
selected the second dropdown is populated with a list of
the food belonging to the selected category (this part is
working fine).

Now I also have a repeater control on the page. When a
food in the second dropdown is selected I want the
nutritional data for it to be bound to the repeater. When
the food is selected the selected value that is sent to
the server always appears to be -1 (the place holder that
appears first in the dropdown) and when the page reloads
the food I chose is no longer selected.

I am not sure what I am doing wrong that causes the
selected value to get lost. I have included the code and
would appreciate any help. Viewstate is enabled on all
controls.

Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Dim conOSOR As SqlConnection
Dim cmdSelectFoodCategories As SqlCommand
Dim dtrFoodCategories As SqlDataReader

conOSOR = New SqlConnection(AppSettings
("connString"))
conOSOR.Open()

cmdSelectFoodCategories = New SqlCommand
("SELECT FC_ID,FC_Category_Description FROM FoodCategories
ORDER BY FC_Category_Description", conOSOR)

dtrFoodCategories =
cmdSelectFoodCategories.ExecuteReader()
DropFoodCategories.DataSource =
dtrFoodCategories
DropFoodCategories.DataTextField
= "FC_Category_Description"
DropFoodCategories.DataValueField = "FC_ID"
DropFoodCategories.DataBind()
DropFoodCategories.Items.Insert(0, New ListItem
("-- select category --", -1))
dtrFoodCategories.Close()
conOSOR.Close()
End If
End Sub

Sub DropFoodCategories_SelectedIndexChanged(ByVal
sender As System.Object, ByVal e As System.EventArgs)
Handles DropFoodList.SelectedIndexChanged
Dim conOSOR As SqlConnection
Dim cmdSelectFoodList As SqlCommand
Dim dtrFoodList As SqlDataReader

conOSOR = New SqlConnection(AppSettings
("connString"))
conOSOR.Open()

cmdSelectFoodList = New SqlCommand("SELECT
F_ID,F_Name FROM Food WHERE F_Category_ID = " &
DropFoodCategories.SelectedValue & " ORDER BY F_Name ",
conOSOR)

dtrFoodList = cmdSelectFoodList.ExecuteReader()
DropFoodList.DataSource = dtrFoodList
DropFoodList.DataTextField = "F_Name"
DropFoodList.DataValueField = "F_ID"
DropFoodList.DataBind()
DropFoodList.Items.Insert(0, New ListItem("--
select food --", -1))
dtrFoodList.Close()
conOSOR.Close()
End Sub

Sub DropFoodList_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DropFoodList.SelectedIndexChanged
Dim conOSOR As SqlConnection
Dim cmdSelectFoodData As SqlCommand
Dim dtrFoodData As SqlDataReader
Dim itemID As String

conOSOR = New SqlConnection(AppSettings
("connString"))
conOSOR.Open()

cmdSelectFoodData = New SqlCommand("SELECT * FROM
FOOD WHERE F_ID = " & DropFoodList.SelectedValue & " ",
conOSOR)

dtrFoodData = cmdSelectFoodData.ExecuteReader()
rptFoodData.DataSource = dtrFoodData
rptFoodData.DataBind()
dtrFoodData.Close()
conOSOR.Close()

End Sub
Nov 19 '05 #1
0 1341

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

Similar topics

46
by: Kingdom | last post by:
In my data base I have a list of componet types e.g. type A - I have 8 off - type B I have 12 off etc. I'm using Set objRS = objDC.Execute("Select DISTINCT Component_Type FROM Parts_Table") ...
1
by: Martial Spirit | last post by:
Hello- I was amazed at the suckerfish drop-downs from AListApart.com. They work great except for one thing, if I position the drop-downs over an iframe element, on mouseover the menus disappear....
3
by: Reb | last post by:
Hi, I am using drop down menu in my pages. In one of my page,there is a listbox control below the menu. This listbox control is hiding the drop down menu items. How can i make the drop down...
0
by: Pat Sagaser via .NET 247 | last post by:
I'm using a repeater with a dynamic template. I don't know the fields to display (or how many) until runtime. I have everything working except for linking Button events to the repeaters ItemCommand...
1
by: Timothy V | last post by:
Hi, If i have an array of arrays (ie, array of int arrays), and i want to use a repeater (for the array) that has a drop down list (for the int arrays), how do I do it? Thank you very much in...
1
by: Mike | last post by:
I have 2 drop downs on my web page and this will allow the user to filter the data on one drop down or both. How can I link these dropdowns together to allow the user to filter on one or both? ...
0
by: dutone | last post by:
I have searched high and low for a solution to this and I dont think its possible.... but I hope not. What I have is a list of items with various values that can be changed via a drop down. Each...
3
by: CSharpguy | last post by:
I have 3 drop downs that are populated from the databasem 4 of my web pages need to have this drop down, how can I trap the selection made in the drop down and popuate my grid on my form?
1
by: JackInDaBox | last post by:
Hello, I am new to this and have run into a small problem. I am using the Ajax toolkit with VS 2005 to fill some drop downs through a web service and it works great. All of the cascading drop...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.