问题描述:

This question already has an answer here:

  • The multi-part identifier “TextBox1.Text” could not be bound in C# ASP.NET?

    3 answers

网友答案:

This is due to loading second combobox while filling data in first combo.
You can avoid this error by:
1. Use SelectionChangeCommitted event instead of SelectedIndexChanged event.
Or
2. Detach selected index change event, populate combobox, attach event again as:

private void frm2_Load(object sender, EventArgs e)
{
   //Detach event
   comboBox1.SelectedIndexChanged -= comboBox1_SelectedIndexChanged;

    //Populate Combobox1
    SqlDataAdapter da = new SqlDataAdapter("SELECT CategoryID, Name FROM Categories", clsMain.con);
    DataSet ds = new DataSet();
    da.Fill(ds);
    comboBox1.DataSource = ds.Tables[0];
    comboBox1.DisplayMember = "Name";
    comboBox1.ValueMember = "CategoryID";

   //Attach event again
    comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged;
}

Hopes this will help you.

相关阅读:
Top