rai nalasa rai nalasa - 2 years ago 149
MySQL Question

bind data on dropdownlist

I'm trying run this code

private void LoadProdName()
cmd = new SqlCommand(@"SELECT productName
FROM Products3
WHERE productType = @Type",con);


da = new SqlDataAdapter(cmd);
dt = new DataTable();
ddlProdName.DataSource = dt;

my selectedIndesChange codes:

protected void ddlProducts_SelectedIndexChanged(object sender, EventArgs e)

which uses the value of my first dropdownlist.My problem is whenever I select a ProductType on my dropdownlist it will fill my second DDL with the select query but I am not getting any data at all from my second dropdownlist.

Now I'm getting some progress.
This is what I get now:
enter image description here

Answer Source

For cascade drowdownlist you must do a postback in your dropdownlist event "OnSelectedIndexChanged" or use an AJAX call to your method

try this guide: http://www.aspsnippets.com/Articles/Creating-Cascading-DropDownLists-in-ASP.Net.aspx

try this code after your query

        ddlProdName.DataSource = cmd.ExecuteReader();

        ddlProdName.DataTextField = "productName";

        ddlProdName.DataValueField = "productName"; //or productId

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download