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 Mike Lewis 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.
 
Put a break point at the start of your submitbutton.click event. Then use F8 to walk through the code. If I had to guess, I'd say there's something refreshing the dataset that's attached to the list. If you can't figure it otu that way, post the code you're using in the submit button so we can see what's going on.
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top