I am trying to bind 2 combo box, being the value of the second dependent from de first.
All the solutions that i saw to this problem were by the use of Sql.Data (Datatable), which i cant use, due to the architecture of the application.
I can do it 2 ways, by c# or through ASP Object Data Source. I’ve trying this approach with any sucess. It is possible to do this?
if (!Page.IsPostBack) { recursohumano rh = new RecursoHumano(); rdpUnidade.DataValueField= "ID" rdpUnidade.DataTextField= "NomeUnidade" rdpUnidade.DataSource= new BLLUnidade().GetAll(); rdpUnidade.DataBind(); rdpInvestigador.DataValueField= "ID" rdpInvestigador.DataTextField= "Nome" rdpInvestigador.DataSource= new BLLRecursoHumano().GetAll(); rdpInvestigador.DataBind(); rdpInvestigador.Items.Insert(0, new RadComboBoxItem("", "")); //rdp investigador should depend on rdpUnidade private void rdpUnidade_SelectedIndexChanged(object sender, EventArgs e) { recursohumano rh = new RecursoHumano(); var InvUnidade = from recursohumano in rh.recursohumano where recursohumano.id == Convert.ToInt32(rdpUnidade.SelectedValue) select recursohumano; rdpInvestigador.DataValueField= "ID"; rdpInvestigador.DataTextField= "Nome"; rdpInvestigador.DataSource = new BLLRecursoHumano().GetAll() }
Advertisement
Answer
The original approach was right, but i was missing a query to List the wanted values:
var res = RecHumano.GetAll().Where(x => x.IDUnidade == id).ToList()