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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DYNAMIC DROPDOWNLIST

Status
Not open for further replies.

barrykellett

Programmer
Mar 4, 2003
29
GB
How do I retain information from a dynamically created drop down list when the list posts back to the server? I think that is my problem when i try to use the selected item in a dropdownlist as the selection is in a different sub procedure than the creation of the list.

has a very good article on dynamically creating a drop down list. How do I reference an item from this dynamically created list?I have tried using; lstcategory.SelectedItem.Value, however when i choose from the list i want the chosen item to be inserted into my new sql query using the following code:

cmdSelectProducts = New OleDbCommand( "Select * From Products Where Prod_type= '@Type'" , conProducts)
cmdSelectProducts.Parameters.Add( "@Type", lstcategory.SelectedItem.Value)

It doesnt return any errors, but it returns nothing when it should obviously return several items as the product type list is generated from the database.

I have the autopost back property of my drop down list set to true, and I think that when the dropdownlist is changed the actual parameter insertion into the SQL Query is entering a blank string, hence no results. If i hard code the text into the query it returns the necessary items.
 
before you repopulate the dropdownlist, check for the ispostback property and then return the value..

Kind of like ...
If Not IsPostBack Then
Dim da As New SqlClient.SqlDataAdapter("select pcname, 'Plaza ' + right(rtrim(pcname),3) as MilePost from serverlist where role='Server'", sc)
Dim dt As New System.Data.DataTable("servers")
Try
da.Fill(dt)
Catch ex As Exception
Response.Write(ex.Message)
Response.End()
End Try
lstPlaza.DataSource = dt
lstPlaza.DataTextField = "MilePost"
lstPlaza.DataValueField = "PcName"
lstPlaza.DataBind()
chkLane.Visible = False
Else
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top