Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating a drop down list with data returned from a stored procedure

Status
Not open for further replies.

hbutt

Programmer
Apr 15, 2003
35
GB
Hi there,

im creating a basic application, where a user will select a value from a drop downlist (list1) . the value selected in list1 is stored in a variable and passed to a stored procedure which brings back the data for list2.

so far i can get list2 populated but when i to select an option in list2 and click submit the list value is reset to the first value in the list.

i have disabled autopostback for list2 and still get the same problem.

any help will be much appreciated.
 
You'll have to check if the page is a postback in the page load event


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
hi,

list1 has postback and is checked in the page load so it doesnt keep doing so continuously, using the :

If Not Page.IsPostBack Then

method, which seems to work for it, its just list2 which uses the value selected in list1 for a stored proc to bring back the corresponding values.

thanks for your help.
 
can we have some code snippets???

Known is handfull, Unknown is worldfull
 
Here is the sub procedure that should load the list:

Sub Load_list2()

Dim conn As New SqlConnection(SqlConnection_1)
Dim cmd As New SqlCommand("[Causes_Clause]", conn)
Dim da As New SqlDataAdapter(cmd)

cmd.CommandType = CommandType.StoredProcedure
dataset1 = New DataSet

cmd.Parameters.Add(New SqlParameter("@field1_val", System.Data.SqlDbType.NVarChar, 50, "field1")).Value = list1_value

da.Fill(dataset1, "tbl_List_Causes")

For Each datarow In dataset1.Tables("tbl_List_Causes").Rows
Dim dataItem As ListItem
dataItem = New ListItem(datarow.Item("field2"), dr.Item(0))
CauseDroplist.Items.Add(dataItemItem)
Next
conn.Close()
End Sub


as for the submit button that converts the values selected in the list to text so they can be added to a label to see all the data that will be brought back.

thanks for the help you've given anymore help would be much appreciated.
 
when exactly are u calling the sub "Load_list2()".

one more thing, why not use inbuilt databinding methods?


>>list value is reset to the first value in the list.
we are talking bout list 2 right???

Known is handfull, Unknown is worldfull
 
yes list2.

load_list2() will be executed when a value is selected from list1.

the value from list1 is then converted to a string and passed to the stored procedure which is then fired off and returns the CORRECT results.

but when i click submit the selected value in list2 defaults back to the first value in the list. i hope this is helpful.

thank you for your help
 
can i also have a look at your submit button code? your list2 code seems to be correct...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top