dl is object of DAL class private void Frm_Incentives_Load(object sender, EventArgs e) { dl.Fn_Select(cmbCostCenter); } private void cmbCostCenter_SelectedIndexChanged(object sender, EventArgs e) { if(cmbCostCenter.Items.Count>0) { dl.Fn_Select_WithParametre(cmbCostCenter.SelectedValue.ToString(),cmbEmployee); } } ===============DAL======== internal void Fn_Select(ComboBox combo) { try { con.Open(); cmd = new SqlCommand("select CCN,CCn_Name from Dept ", con); adpt = new SqlDataAdapter(cmd); adpt.Fill(ds); combo.Items.Clear(); if (ds.Tables[0].Rows.Count > 0) { combo.DataSource = ds.Tables[0];//Error combo.DisplayMember = ds.Tables[0].Columns[1].ToString(); combo.ValueMember = ds.Tables[0].Columns[0].ToString(); } con.Close(); } catch(Exception ex) { con.Close(); } } internal void Fn_Select_WithParametre(string code,ComboBox combo) { try { con.Open(); cmd = new SqlCommand("select Emp_Code,Emp_Name from Master where CCN="+code+" ", con); adpt = new SqlDataAdapter(cmd); adpt.Fill(ds); combo.Items.Clear(); if(ds.Tables[0].Rows.Count>0) { combo.DataSource = ds.Tables[0]; combo.DisplayMember = ds.Tables[0].Columns[3].ToString(); combo.ValueMember = ds.Tables[0].Columns[4].ToString(); con.Close(); } } catch (Exception ex) { con.Close(); } }
SelectedIndexChanged
SelectionChangeCommitted
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)