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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RK800
    New Member
    • Feb 2008
    • 1

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

    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 selectedindexch ange event of dd2. i get the values inside dd2, but does not respond to any event. i am using

    the code is as below.

    [code=asp]
    Function getdatafromdb(B yVal s As String) As String

    Try
    dtChild = New DataTable
    Select Case Trim(s).ToUpper
    Case UCase("sivsetup id"), UCase("sub"), UCase("subclien t"), UCase("edm_id") , UCase("convrt_w ho"), UCase("audit_wh o"), UCase("siv_inje ct"), UCase("engine_b uilt"), UCase("audit")
    'Session("tblna me") = "p"
    qrystr2 = "select distinct " + Trim(s) + " from edi_parent order by " + Trim(s) + ""
    Case UCase("carrname "), UCase("scac")
    qrystr2 = "select distinct " + Trim(s) + " from carreuro order by " + Trim(s) + ""
    'Session("tblna me") = "ca"
    Case UCase("clientna me"), UCase("clientno ")
    'Session("tblna me") = "cl"
    qrystr2 = "select distinct " + Trim(s) + " from clientdt order by " + Trim(s) + ""
    End Select

    mycmd = New MySqlCommand(qr ystr2, myconn)
    mycmd.CommandTi meout = 0
    adap = New MySqlDataAdapte r(mycmd)
    adap.Fill(dtChi ld)

    Dim ddlfiltervalue As New DropDownList
    ddlfiltervalue. ID = "ddlfiltervalue "
    ddlfiltervalue. DataSource = dtChild
    ddlfiltervalue. Items.Add("--SELECT--")
    ddlfiltervalue. DataTextField = s
    ddlfiltervalue. DataBind()
    Me.Controls.Add (ddlfiltervalue )

    Dim sw As New StringWriter
    Dim htw As New HtmlTextWriter( sw)
    ddlfiltervalue. RenderControl(h tw)
    Return sw.ToString
    Catch ex As Exception
    Response.Write( "Error filling data in child Grid" + ex.Message)
    Finally
    myconn.Close()
    End Try
    End Function
    [/code]
  • markrawlingson
    Recognized Expert Contributor
    • Aug 2007
    • 346

    #2
    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
    [code=html]
    <select name="oWhatever " OnChange="SomeJ SFunction();">

    </select>
    [/code]

    Sincerely,
    Mark

    Comment

    Working...