Filter DropDownList data with another DropDownList

0

At the moment of selecting a data in the first DropDownList1 , in the second DropDownList2 , it will filter with an query of SQL and the new data will be placed in its list.

At the moment I only have this method:

public void dropdowns() {

    SqlConnection cn = new SqlConnection("CadenaDeConexion");
    SqlCommand cmd = new SqlCommand("select CustomerNumber FROM tbl_Customer where CustomerSitie='"+DropDownList1.Text +"'", cn);
    cn.Open();
    SqlDataReader leer = cmd.ExecuteReader();
    if (leer.Read() == true)
    {
            DropDownList2.Text = leer["CustomerNumber"].ToString();
    }
    cn.Close();
}

But do not fucniona with TextChanged , only with button:

protected void DropDownList2_TextChanged(object sender, EventArgs e)
{

    dropdowns();
}
protected void Button2_Click(object sender, EventArgs e)
{
    dropdowns();
}
    
asked by CarlosR93 18.01.2017 в 17:32
source

1 answer

0

My friend must use the event, Selected_Changed.

<asp:DropDownList AutoPostBack="true" runat="server" ID="myListDropDown" 
                CssClass="text" OnSelectedIndexChanged="myListDropDown_Change" />
    
answered by 19.01.2017 в 18:22