有一个webform窗体,当点击查询信息按钮时会出现好多信息,当我点击其中一条信息中的一条数据时,数据会出现在下面的要修改的textbox中,可是我有的信息不需要修改就空在那,就填要修改的框,最后运行时数据库里面的信息就变了,我没点击修改的信息就变成空白了,怎么回事啊?而且变一条信息下面一列的数据都成一样的了

解决方案 »

  1.   

     private void button2_Click(object sender, EventArgs e)
            {
                if (MessageBox.Show("确定要修改吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    sqlondmc.SQL = "update Teacher_Info set  Class='" + comboBox2.SelectedIndex + "',Subject='" + textBox3.Text.Trim() + "',Address='" + textBox4.Text.Trim() + "',Tel='" + textBox2.Text.Trim() + "' where Teacher_ID='" + textBox5.Text.Trim() + "'";
                    sqlondmc.ReturnDataSet();            }
            }        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
            {
                comboBox2.Text = dataGridView1[4, dataGridView1.CurrentCell.RowIndex].Value.ToString();
                textBox3.Text = dataGridView1[5, dataGridView1.CurrentCell.RowIndex].Value.ToString();
                textBox4.Text = dataGridView1[7, dataGridView1.CurrentCell.RowIndex].Value.ToString();
                textBox2.Text = dataGridView1[6, dataGridView1.CurrentCell.RowIndex].Value.ToString();
                textBox5.Text = dataGridView1[0, dataGridView1.CurrentCell.RowIndex].Value.ToString();        }
    为什么班级中显示的数据时0呢
      

  2.   

    我怀疑你时间用错了,点击行不要用CellContentClick事件,应该用CellClick事件
      

  3.   

    comboBox2.SelectedIndex...应该是text呢