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?
C#
...
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()
}
...
Sachin SinghRank #66 · 26.2K reputationPosted Oct 19, 2021, 12:46 AM EDT
if your GetAll() method returns a List and the list has multiple recursohumano.id, then the below code must return all the matching rows, otherwise, you need to look at the sql for GetAll() and what it returns, whether it includes the Id or not, also the selected value is giving you the id or not.
RecHumano.GetAll().where(x=>x.id==id).ToList();
Sachin SinghRank #66 · 26.2K reputationPosted Oct 18, 2021, 1:36 PM EDT
Rijwan AnsariRank #82 · 24.2K reputationPosted Oct 18, 2021, 1:56 PM EDT
Srinivasan RamamoorthiRank #877 · 2.5K reputationPosted Oct 18, 2021, 2:23 PM EDT
Harlem 98143 reputationPosted Oct 18, 2021, 3:19 PM EDT
Harlem 98143 reputationPosted Oct 19, 2021, 5:38 AM EDT