ahmed sa

ahmed sa

  • NA
  • 289
  • 129.5k

retrieve data from combobox in selectedindexchanged problem

Feb 11 2014 7:47 AM
I have combobox i want to show data in selectedindex changed event but it not accept although this code retrieve data in load event of form

private void bind1()

{


con.Open();

da = new SqlDataAdapter("Select NationalityID,NationalityName from Nationality", con);

dt = new DataTable();

da.Fill(dt);


SqlConnection con = new SqlConnection("Data Source=" + value1 + ";Initial Catalog=" + value2 + ";User ID=" + value3 + ";Password=" + value4 + "");// DataRow dr;


dr = dt.NewRow();


dr.ItemArray = new object[] { 0, "---Select Nationality---" };


dt.Rows.InsertAt(dr, 0);

comboBox2.DisplayMember = "NationalityName";

comboBox2.ValueMember = "NationalityID";

comboBox2.DataSource = dt;

comboBox2.Refresh();

con.Close();

}

private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)

{

bind1();

}

this code above work fine and retrieve data in combobox by load event but i need to work in selected index changed event combobox

Why not retrieve data in selected index changed event of combobox

and how i do that


Answers (6)