Connecting Tech Pros Worldwide Help | Site Map

How do i handle the Selected Index Changed event of a dynamic DropDownList

Newbie
 
Join Date: Feb 2008
Posts: 1
#1: Feb 26 '08
could someone help me out with this??

i am creating a dropdown(dd2) dynamically inside a <div> , on the selected index event of another dropdown(dd1). somehow i am not able to handle or get the selectedindexchange event of dd2. i get the values inside dd2, but does not respond to any event. i am using

the code is as below.

Expand|Select|Wrap|Line Numbers
  1. Function getdatafromdb(ByVal s As String) As String
  2.  
  3. Try
  4. dtChild = New DataTable
  5. Select Case Trim(s).ToUpper
  6. Case UCase("sivsetupid"), UCase("sub"), UCase("subclient"), UCase("edm_id"), UCase("convrt_who"), UCase("audit_who"), UCase("siv_inject"), UCase("engine_built"), UCase("audit")
  7. 'Session("tblname") = "p"
  8. qrystr2 = "select distinct " + Trim(s) + " from edi_parent order by " + Trim(s) + ""
  9. Case UCase("carrname"), UCase("scac")
  10. qrystr2 = "select distinct " + Trim(s) + " from carreuro order by " + Trim(s) + ""
  11. 'Session("tblname") = "ca"
  12. Case UCase("clientname"), UCase("clientno")
  13. 'Session("tblname") = "cl"
  14. qrystr2 = "select distinct " + Trim(s) + " from clientdt order by " + Trim(s) + ""
  15. End Select
  16.  
  17. mycmd = New MySqlCommand(qrystr2, myconn)
  18. mycmd.CommandTimeout = 0
  19. adap = New MySqlDataAdapter(mycmd)
  20. adap.Fill(dtChild)
  21.  
  22. Dim ddlfiltervalue As New DropDownList 
  23. ddlfiltervalue.ID = "ddlfiltervalue"
  24. ddlfiltervalue.DataSource = dtChild
  25. ddlfiltervalue.Items.Add("--SELECT--")
  26. ddlfiltervalue.DataTextField = s
  27. ddlfiltervalue.DataBind()
  28. Me.Controls.Add(ddlfiltervalue)
  29.  
  30. Dim sw As New StringWriter
  31. Dim htw As New HtmlTextWriter(sw)
  32. ddlfiltervalue.RenderControl(htw)
  33. Return sw.ToString
  34. Catch ex As Exception
  35. Response.Write("Error filling data in child Grid" + ex.Message)
  36. Finally
  37. myconn.Close()
  38. End Try
  39. End Function
  40.  
markrawlingson's Avatar
Moderator
 
Join Date: Aug 2007
Location: Bowmanville, Ontario
Posts: 329
#2: Feb 26 '08

re: How do i handle the Selected Index Changed event of a dynamic DropDownList


Hi rk800,


Please use code tags when you post. It makes it difficult for us to sift through code in order to help you when the code isn't formatted. Instructions for this are on the right when you post.

As per your problem, I think you're trying to perform a certain action when someone chooses an option from the first drop down, you'd like to do something to second drop down? Or do you just want to know generically how to handle changes with the selectedIndex of a drop down list?

If neither of these are the case please be more clear as to what you are trying to achieve.

To handle the selectedIndex changes of a drop down list, you need to use the OnChange event in javascript which fits into your <Select> tag.

EG
Expand|Select|Wrap|Line Numbers
  1. <select name="oWhatever" OnChange="SomeJSFunction();">
  2.  
  3. </select>
  4.  
Sincerely,
Mark
Reply